GetURL not firing after uploading file to Google Drive

Hello! I’m trying to build a “report error” form in my app that submits to Google Sheets. Ideally, users can submit up to 3 pictures at a time. I’ve followed TimAI2 tutorials and gotten the upload working with the extension Juan Antonio wrote, but hit a brick wall after that.
The page has a text input section for a description of the error, a text input for the project ID as users are working on several projects at once, and camera/image picker options.

I’m thinking the process should go something like this:

  • Convert image to base64 file and get relevant data (done)
  • Run the webapps script and decode base64 string back to image, add to relevant folder (done)
  • On successful upload, return a text string with the download URL (problem)
  • Save text string to [variable] and submit a Google Form with the download URL as answer to a Short Answer question (doable, once I get the previous step working)

I’ve tried returning a different string than the one shown in the tutorials, JSON stringify sequences, and a couple of different getURL() methods in Google Apps Script, but always get {“Result”:“Success”} in the app instead of the new text string. Help?

Please show your google apps script, you probably just need to modify the contentService Output.

What a google drive download url should look like:

https://ai2.metricrat.co.uk/scraps/show-an-image-from-google-drive-in-your-ai2-app

(You only need to get the FileID, you can build the rest)

function doPost(e) {
  var data = Utilities.base64Decode(e.parameters.data);
  var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
  var imageID = DriveApp.getFolderById('censored but works').createFile(blob).getId();
  return ContentService.createTextOutput("https://drive.google.com/uc?export=view&id="+imageID);
   }

After I changed the blocks to point to this script, Notifier will call up the progress dialogue and the picture does upload, but Web1 never triggers the GotText event (which is supposed to dismiss the circle of doom). I also have a Label that’s supposed to change to show the URL as a string, so I’m not too bothered by what’s between uc? and id= for now.

Found a workaround posted earlier that solved it. I just wasn’t phrasing the Google query correctly. Thanks!

The script you have posted works?

What did you have to change to make it all work? It is always helpful to know, and may help others…

I modified the script given in the tutorial as shown below, since I don’t care about location data:

function doPost(e) {
  if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat) {
    return message("Error: Bad Params");
  } else {
    var imgf = e.parameters.imageformat[0].toUpperCase();
    var mime =
        (imgf == 'BMP')  ? MimeType.BMP
      : (imgf == 'GIF')  ? MimeType.GIF
      : (imgf == 'JPEG') ? MimeType.JPEG
      : (imgf == 'JPG')  ? MimeType.JPEG
      : (imgf == 'PNG')  ? MimeType.PNG
      : (imgf == 'SVG')  ? MimeType.SVG
      : false;
    if (mime) {
      var data = Utilities.base64Decode(e.parameters.file, Utilities.Charset.UTF_8);
      var blob = Utilities.newBlob(data, mime, e.parameters.filename);
      var filename = e.parameters.filename;
      
      var imageID = DriveApp.getFolderById('FOLDERID').createFile(blob).getId();
      
      var jobID = e.parameters.jobname[0];
      var desc = e.parameters.desc[0];
      var issue = e.parameters.issue[0];
      var dlurl = "https://drive.google.com/uc?export=download&id=" + imageID;
      
      var ss = SpreadsheetApp.getActive();
      var sh = ss.getSheets()[0];
      sh.appendRow([jobID,desc,issue,dlurl]);
      
      return message("Success: Image Uploaded");
    } else {
      return message("Error: Please Try Again");
    }
  }
}

function message(msg) {
  return ContentService.createTextOutput(msg);
}

This accomplishes exactly what I set out to do without the intermediate step of submitting a Google Form tied to the spreadsheet (to capture the job name, issue category, and description). I imagine if a developer wanted to get an upload link returned for their own use, they could set a Web to “read” the final row of the same sheet they’re writing to.

Here are my blocks, with the irrelevant ones minimized. The UploadCounter is the beginning of a system for multiple uploads attached to the same error report.

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