I have been uploading effortlessly files to S3 as buffers but the source was via file Upload from the client Side either from postman or a frontend app. This is how it looks usually
{type: buffer, data: buffer} or {type: buffer, data: [buffer]}
anyways, I am able to get the desired buffer to pass to S3 and the result is an S3 url that is an actual image which is downloadable.
New Issue: I got an sql file that contains a column for images stored as MEDIUMBLOB. This is how it looks in the table below.
I am not able to upload it as a buffer to S3.
I have fetched the content of the table via nodejs and I got data for each row as;
RowDataPacket {
employee_id: 000,
data: <Buffer ef bf bd 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 ef bf bd 00 00 00 ef bf bd 08 02 00 00 00 ef bf bd 38 58 ef bf bd 00 00 ef bf bd 00 49 ... 111181 more bytes>
}
I have this piece of code that just sends that buffer
const buff = result.data;(*data is the buffer as shown in the code snippet above*)
s3.upload(
{
Bucket: bucketName,
Body: buff,
Key: key
}
the result is an S3 url which I expect, but on downloading it, it shows the same image as shown in the screenshot above instead of a real image.
I have made some research to try find a solution, but so far, I have not managed to get a solution that works for me.
But I have tried to upload a file on postman and get a buffer and convert it to base64 then I was able to get the equivalent image. So not really sure if the image in the mysql table is corrupted or hence the buffer I am getting cannot be transformed to a proper image.
The closest to my question is this Similar Issue I had
The difference with this and mine is that the Buffer here is coming in the format which I am also used to and I won't have an issue passing that Buffer to the S3 to get the desired result. But mine is coming from mysql
I am really stuck on this and not sure how to find my way around it.