Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image in database

Is it possible to store an Image file (.jpg, .gif, etc) in MYSQL database? Or do it just stores in system and takes reference path of image?

I am using ASP.NET C#, so if you have sample code, it would be great if you could share it.

like image 824
Karthik Malla Avatar asked Feb 24 '11 21:02

Karthik Malla


1 Answers

Yes, you can store image files (and any other files) in a database as binary data.

In MySQL, the BLOB data type can be used to accomplish this.

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. [...]

BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.

like image 194
Donut Avatar answered Sep 20 '22 20:09

Donut