Send more Image and data Location to GoogleSheet single row

Based TIMAI2 guide.
[https://groups.google.com/g/mitappinventortest/c/liWppNXqHXM?pli=1]
its work .

But how to add two imageID to single row Google sheet

this my google sheet target [https://docs.google.com/spreadsheets/d/1hjiEfjWD0ta6vZ5ajlOOz4FNQFS5JeoqA--GF0p_eLM/edit?usp=sharing]


In Google drive 2 Image was create, but it cant send data image to google sheet.
maybe my problem with app script because im newbie
thank so much

You should send only one post command, including the second image details as additional parameters, then edit the apps script to handle the second image parameters, in order for its details to be added to the same appendRow command, therefore both images will be listed on the same row of the spreadsheet.

1 Like

Not tested, but this amended google apps script should handle the additional image parameters:

function doGet(e) {
 return message("Error: Please Try Again");
    
}

var data,blob,data2,blob2;

function doPost(e) {
  if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat || !e.parameters.filename2 || !e.parameters.file2 || !e.parameters.imageformat2) {
    return message("Error: Please Try Again");
  } else {
    var imgf = e.parameters.imageformat[0].toUpperCase();
    var imgf2 = e.parameters.imageformat2[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;
      
      var mime2 =
        (imgf2 == 'BMP')  ? MimeType.BMP
      : (imgf2 == 'GIF')  ? MimeType.GIF
      : (imgf2 == 'JPEG') ? MimeType.JPEG
      : (imgf2 == 'JPG')  ? MimeType.JPEG
      : (imgf2 == 'PNG')  ? MimeType.PNG
      : (imgf2 == 'SVG')  ? MimeType.SVG
      : false;

      if (mime && mime2) {    
      data = Utilities.base64Decode(e.parameters.file, Utilities.Charset.UTF_8);
      blob = Utilities.newBlob(data, mime, e.parameters.filename);
        
      data2 = Utilities.base64Decode(e.parameters.file2, Utilities.Charset.UTF_8);
      blob2 = Utilities.newBlob(data2, mime2, e.parameters.filename2);
      
      var imageID = DriveApp.getFolderById('1AvjKBusD5jCHttEXA24VRGVTYJIv7CyP').createFile(blob).getId();
      var imageID2 = DriveApp.getFolderById('1AvjKBusD5jCHttEXA24VRGVTYJIv7CyP').createFile(blob2).getId();
      var lat = e.parameters.lat[0];
      var lon = e.parameters.lon[0];
      var add = e.parameters.address[0];
      var name = e.parameters.filename[0];
      var name2 = e.parameters.filename2[0];
      var viewurl = "https://drive.google.com/uc?export=view&id=" + imageID;
      var viewurl2 = "https://drive.google.com/uc?export=view&id=" + imageID2;
      var ss = SpreadsheetApp.getActive();
      var sh = ss.getSheets()[0];
      sh.appendRow([lat,lon,add,imageID,name,viewurl,imageID2,name2,viewurl2]);
      
      return message("Success: Image Uploaded and Data Saved");
    } else {
      return message("Error: Please Try Again");
    }
  }
}

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

wow, fast reponse sir. i will try this;
by the way from your script, what mean of these

var lat = e.parameters.lat[0];

why it use

[0];

some tutuorial only

var lat = e.parameters.lat;

im just try understand your script said, thanks

If I remember correctly, each parameter is inside a list, therefore you have to call the first (and only) item from that list, [0] being the first item (javascript starts lists at 0)

1 Like

:open_mouth: great great thanks for TIMAI2, your script work, even you not tested
based your solution this my block;



thaks so much @TIMAI2 :pray: :pray:

thumbsup2

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