I've searched through the Google Apps Script Reference but couldn't find an answer to my question. Can a blob be passed through a .run() function in a Google script? Below is the code I am working with:
Within my HTML file's script, there is only a canvas object and a paragraph element for "print" statements.
<script>
var canvas = document.getElementById('myCanvas');
var can = canvas.getContext("2d");
can.fillRect(20,20,150,100);
var canvasData = canvas.toDataURL('image/png', 1);
var blob = toBlob(canvasData);
document.getElementById('ins').innerHTML = "Got the Blob " + blob.type;
google.script.run.printCanvas(blob);
function toBlob(dataURI) {
// converting base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - refer to SO answer #6850276 for suitable code
document.getElementById('ins').innerHTML = ("Data URI:" + dataURI);
var byteString = atob(dataURI.split(',')[1]);
// separating out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// writing the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// writing the ArrayBuffer to a blob
var blob = new Blob([ab], {type: 'image/png'});
return blob;
}
</script>
The output of blob.type reveals "Got the Blob image/png."
However, when trying to execute .run(blob), an error occurs:
"Uncaught TypeError: Failed due to illegal value in property: 0"
I understand that GAS does not allow passing DIVs, hence I'm uncertain if it's feasible to pass a blob to the .gs file. I'm struggling to determine why the application refuses to run. If possible, please provide guidance on how to achieve this.
It seems like the issue may not lie within the .gs file since the initial line contains a DocumentApp.alert which does not trigger. Thus, it appears that the application isn't reaching the .gs file.