none
save and retrieve images in MySQL RRS feed

  • Question

  • Hi,

    I would like to ask how can I save and retrieve images to / from MySQL using C#? and what's the best datatype to use?


    Thanks
    Sunday, July 20, 2014 8:40 AM

Answers

  • It depends on the maximum size of the images.  See webpage below

    TINYBLOB,               TINYTEXT L + 1 bytes, where               L <    2**8
    BLOB, TEXT L + 2 bytes, where               L <    2**16
    MEDIUMBLOB,               MEDIUMTEXT L + 3 bytes, where               L <    2**24
    LONGBLOB,               LONGTEXT L + 4 bytes, where               L <    2**32

    Your image is probably greater than 256 bytes so TINY is no good.  If you can use BLOB than use Encoding.Unicode to pack the bytes to 16 bits.  Otherwise, I wouild use BinaryWriter/BinaryReader to convert the bytes array tolong.  If you byte array isn't always a multiple of 4, I would add a byte count to the beginning of the data so you always unpack the data to the same number of bytes you started with. 

    http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html


    jdweng


    Sunday, July 20, 2014 12:12 PM