2

I am using php and intervention

What is the db format of a blob?

Is MySQL saving it as base64?

Before I save an image file to db what should I do?

Image::make('......')->encode('data-url');

Is that it?

2
  • blob stands for "Binary Large OBject". The data inserted should be binary, such as an image, not base64 encoded. You could use base64 to encode data while in transit, but it should be decoded when stored in a blob field. Commented Nov 2, 2016 at 22:33
  • @JonathanKuhn so if I provide a File parameter for the column it is OK? Commented Nov 2, 2016 at 22:35

1 Answer 1

5

How to store a Binary Large Object (BLOB)?

  • A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB.
  • These differ only in the maximum length of the values they can hold.
  • The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

Hope the following code will help you:

CREATE TABLE IMAGE_TABLE(
    IMG_ID INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    IMG_DETAILS CHAR(50),
    IMG_DATA LONGBLOB,
    IMG_NAME CHAR(50),
    IMG_SIZE CHAR(50),
    IMG_TYPE CHAR(50)
);

This will create a table which will suit your requirement.

You may also refer the following SO answers:

You can refer the official documentation here. This link and this link would be worth a read to deepen your understanding.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.