I'm receiving a base64encoded image in a Google Sheets script. I can successfully generate an image by logging
e.postData.contents
then using https://www.base64decode.org/ to decode and generate a .jpg file. But when I try to do the decoding inside the google script and write a jpg file to drive, it is corrupted. It looks similar, but there are some replacement characters inserted. Here's my code:
function doPost(e) {
var decoded = Utilities.base64Decode(e.postData.contents, Utilities.Charset.UTF_8);
var blob = Utilities.newBlob(decoded);
DriveApp.createFile('img_'+date+'.jpg', blob.getDataAsString('Windows-1252'), MimeType.JPEG);
}
I also tried blob.getAs('image/jpeg'), but that just returns a 4-byte file containing the text Blob.
Any ideas? I've tried a few different charsets, and Windows-1252 seems to give the closest results.