I am using the MySql Connector C++ to store a JPEG image from a file into the database. I am using the prepared statement. After execution of the prepared statement, only the
The issue lies in the constructor of the image file:
std::ifstream blob_file(filename.c_str());
This should have the binary mode attribute:
std::ifstream blob_file(filename.c_str(), std::ios_base::binary);
The file, a JPEG image, is binary data.
Also, the hex dump at byte 65 shows 1a
, which is the Windows OS end of file character:
0000040 1a14 1115 1811 1821 1d1a 1f1d 1f1f 1713
After fixing the constructor, the MySql shows the data size:
mysql> SELECT ID_Picture, LENGTH(Image_Data)
-> FROM picture_image_data
-> WHERE ID_Picture = 1;
+------------+--------------------+
| ID_Picture | LENGTH(Image_Data) |
+------------+--------------------+
| 1 | 18453 |
+------------+--------------------+
1 row in set (0.00 sec)