Error uploading images to Driver and data to Google Sheet

I want to upload image to Driver and data + imageID to GGsheet
But I got error: data+imageID failed to upload to GGsheet, and Error uploading two images to Driver.
ACukuploadimageID.aia (738.8 KB)

I use script to upload data to GGsheet:

var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
function doPost(e) {
var data = JSON.parse(e.postData.contents);
sh.appendRow(data);
return ContentService.createTextOutput(data);
}
function doGet(e) {
var data = JSON.stringify(sh.getDataRange().getDisplayValues());
return ContentService.createTextOutput(data);
}

I use script to upload image to Driver:
function doPost(e) {
var data = Utilities.base64Decode(e.parameters.FILE);
var blob = Utilities.newBlob(data, e.parameters.MIMETYPE, e.parameters.NAMA_FILE);
var fileID = DriveApp.getFolderById(e.parameters.FOLDER_ID).createFile(blob).getId();
if (fileID){
return ContentService.createTextOutput(“Image uploaded successfully”);
}else{
return ContentService.createTextOutput(“Data Failed to Save!”);
}
}

I used 2 separate scripts it worked, but I combined and added the ImageID entry (var viewurl = “https://drive.google.com/uc?export=view&id=” + imageID;)" it was faulty.

I don’t know where I did wrong, or Script error. Please help me!

Script :
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
function doPost(e) {
var data = Utilities.base64Decode(e.parameters.FILE);
var blob = Utilities.newBlob(data, e.parameters.MIMETYPE, e.parameters.NAMA_FILE);
var imageID = DriveApp.getFolderById(‘15TF9OludqfOeJQvhLZzDJEeQDMPaA8i-’).createFile(blob).getId();
var viewurl = “https://drive.google.com/uc?export=view&id=” + imageID;
return ContentService.createTextOutput(viewurl);
var data = JSON.parse(e.postData.contents);
sh.appendRow([data,viewurl]);
if (fileID){
return ContentService.createTextOutput(“Image uploaded successfully”);
}else{
return ContentService.createTextOutput(“Data Failed to Save!”);
}
}



you can refer here to how to upload files to gdrive and get the file id

I tried running the aia file of the article you sent me, but it gave me an error: “Error from Companion: The operation MinSdk cannot accept the arguments: , [empty-string]”.
I don’t know the reason of this error, please help me!


That one is for mit app… if you are using it mean, before connecting to companion you need to set minimum SDK, enable RTL , flashscreen, and all from the settings

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.