I've created a web application that ask users to sign manually a spreasheet document. In order to do it I wrote the code below :
function saveSign(url){ // url = canvas.toDataURL("image/png");
const email = Session.getActiveUser().getEmail();
const base64 = url.split(",")[1];
const decoded = Utilities.base64Decode(base64);
const blob = Utilities.newBlob(decoded, MimeType.PNG, email);
const file = DriveApp.createFile(blob);
return true;
};
This code will create a file with the user email title in each users personal drive who use this web app.
All is well, but when I try to insert the picture just created or already created and stored in the user personal drive on the spreadsheet with the code below, an error occur.
const ssDA = SpreadsheetApp.openById("idSpreadsheet");
const wsDA = ssDA.getSheetByName("sheetName");
let uBlob;
const files = DriveApp.getFiles();
while (files.hasNext()) {
let file = files.next();
let fFileName = file.getName();
if(fFileName === ufileName){
uBlob = file.getBlob();
}
}
wsDA.insertImage(uBlob, 12, 32); // Error in this line
Console log Error :
Exception: Argument non valide : url
When I try to insert an image stored in my Drive all is well but when a colleague try to insert an image stored in his personal Drive the code above doen't work.
Indeed the while loop (var files) iterate in my personal folder and not in the user personal folder.
See below the web app deployement informations :
Execute the app as: User accessing the web app
Could you please help me ?
Exception: Argument non valide : url
occur in your script? 2. AboutAll is well
, can I ask you about the detail of it? 3. Can I ask you about the scopes using in your script? – TanaikewsDA.insertImage(uBlob, 12, 32);
. When I said all is well, I wanted to say that the function saveSign work as well, it mean that users who use the web App. can save the canvas drawing in their own personal drive. The second code with the while loop is triggered after a form submit. The script scopes are listed below :"https://www.googleapis.com/auth/spreadsheets", "userinfo.email", "forms", "script.scriptapp", "script.send_mail", "script.external_request", "drive"
Thks in advance ! – Michael