I would like to decode the image encoded in base64 in gas and save it in blob.
However, the seventh line of Utilities.base64Decode(data);
displays the error Failed to decode the string.
I tried other base64s, but the results didn't change.
The base64 in the code below is Wikipedia-Data URI scheme to
Others were encoded with a service such as Base64 encoder.
If you have any solutions or alternatives, please take care of them.
function writeFile(){
vardrive=DriveApp.getFolderById('<<folder id>>');
varfileName='sample.png';
var contentType='image/png';
vardata='data:image/png;base64,iVBORw0KGgoAAAAANSUhEugAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
vardecoded=Utilities.base64Decode(data);
varblob=Utilities.newBlob(decoded, contentType, fileName)
drive.createFile(blob);
}
The base64 encoded string substituting the variable data is invalid.
I think it would be OK if the first string excluding "data:image/png;base64," was used as the base64 Decode argument.
© 2024 OneMinuteCode. All rights reserved.