I'm having trouble trying to save a JPG image file using file-saver. I have no problems using the same method when saving text files though.
I am pulling a Blob image from a MySQL database and trying to have it download for a user when they click on a button.
When I pull the image record (test.jpg) from the database this is the buffer I receive:
Blob {
buffer: <Buffer 64 61 74 61 3a 69 6d 61 67 65 2f 6a 70 65 67 3b 62 61 73 65 36 34 2c 2f 39 6a 2f 34 41 41 51 53 6b 5a 4a 52 67 41 42 41 51 41 41 53 41 42 49 41 41 44 ... 114553 more bytes>,
[Symbol(closed)]: false,
[Symbol(type)]: 'image/jpeg'
}
I then send this information to file-saver to save this as an image:
console.log("is res real", res)
console.log(res['buffer'].data)
var file = new File([res['buffer'].data], "test.jpg", { type: "image/jpeg" });
FileSaver.saveAs(file);
This is what's logged on the front end console. 
The image succesfully downloads, but when I try opening it I get a black screen with a message saying "It appears that we don't support this file format." which leads me to believe it is getting corrupted somehwere.
Any ideas?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/QirmDpe
Comments
Post a Comment