After piecing together data and scripts from various sources, I have come so close to getting everything working perfectly. However, I've hit a snag on the final stretch...
My current task involves using the dom-to-image library to convert my Container div into a blob for saving to Google Drive.
Here is the JavaScript code snippet:
btn.onclick = function() {
domtoimage.toPng(document.getElementById('app')).then(function (dataUrl)
{
base64 = dataUrl.replace(/^.*,/, "");
console.log(base64);
google.script.run.withSuccessHandler(e => console.log(e)).saveFile(dataUrl);
});
}
The generated string looks correct when checked with , and I can download the image as a PNG successfully.... BUT....
When the data is sent to my GS function:
function saveFile(e) {
var blob = Utilities.newBlob(e, MimeType.PNG, "layout.png");
DriveApp.createFile(blob);
return "Done.";
}
While the function seems to work and creates an "image" file on my Google Drive that is similar in size to the test image downloaded from Code Beautify, Google does not preview it properly. Additionally, Photoshop and other image programs cannot read it as a PNG file. Where am I going wrong? Is it the MimeType syntax or the raw blob data causing the issue?