Database Image

Can I save an image file (.jpg, .gif, etc.) in a MYSQL database? Or is it just stored in the system and accepts the image reference path?

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

+5
source share
6 answers

Take this ... Loading ASP.NET Resized Images You can find many examples.

+1
source

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

In MySQL, you can use BLOBa data type for this .

BLOB - , . BLOB - TINYBLOB, BLOB, MEDIUMBLOB LONGBLOB. , . [...]

BLOB ( ). , .

+6

, , : ?

-, : http://www.dotnetcurry.com/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1

-, , . .

asp.net:

?

- - . . , . 4 . , 6 .

Microsoft, BLOB. , . . . , .

, - ? , , BLOB , .

, ? , . ( , ), . , , .

+4

.

public static byte[] ConvertImageToByteArray(Image imageIn)
{
    var ms = new MemoryStream();
    imageIn.Save(ms, ImageFormat.Png);
    return ms.ToArray();
}

:

public static Image ConvertByteArrayToImage(byte[] byteArrayIn)
{
    var ms = new MemoryStream(byteArrayIn);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
}
+1
+1

BLOB , . GB, 20 . BLOB, .

0

All Articles