I send two different images to g-drive, but same two images created, different ImageID

Based : Send more Image and data Location to GoogleSheet single row

I use two camera components to take two different pictures, the components are named FOTOM and FOTOR, and has successfully submitted images to google drive with @TIMAI2 solution

FOTOM images have been successfully sent to google drive, but now I have problems with FOTOR images, although the images are different but when sent to google drive two images are created, all images are images from FOTOM, the file name comes from FOTOM, but the imageID is different.

this my block for send the image:
blocks (1)


blocks (2)

this app-script

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('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId();

      var imageID2 = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).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 tglscanwil= e.parameters.tglscanwil[0];   

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

var petugasstr= petugas.toString();

        

      var ts = Utilities.formatDate(new Date(), "GMT+8", "dd/MM/yyyy HH:mm:ss");

      var ss = SpreadsheetApp.getActive();

      var sh = ss.getSheets()[0];

        

      sh.appendRow([tglscanwil, nosamb,makhir,m3,kelainanid,nama,alamat,kec,gol,masli,mawal,tglscan,thnbln,petugasstr,

                    diedit,makhir1blnlalu,makhir2blnlalu,makhir3blnlalu,tglhp,

                    latlong,name,viewurl,name2,viewurl2,ts,metodbaca,'=IF(COUNTIF(dataVerify!A:A,INDIRECT("R[0]C[-25]",FALSE)),"VX1","VX0")']);

      

      return message("Success: Image Uploaded and Data Saved");

    } else {

      return message("Error: Please Try Again");

    }

  }

}

function message(msg) {

  return ContentService.createTextOutput(msg);

}

and
google sheet

seems like the block is correct, I even tried to see the contents of the vimageAsBase64 variable. the contents are long text, but they are different from each other, but why does it produce the same image when sent? does the simplebase64 extension not handle two images?

thanks for your helps

I believe this is due to a small error in my original revised script. Check this section:

var imageID = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId();

var imageID2 = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId();

the line for var imageID2 should read:

var imageID2 = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob2).getId();

Change "blob" to blob2"

(Note I have updated this in the other topic as well)

Thanks for fast respond, Sorry late to reply, Will try it later, kids broke my glasses :weary: .

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('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId();
var imageID2 = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').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;

i was changed blob to blob2 at imageID2, still same nothing change

Did you re-publish your script ?

1 Like

yes I think, Google Apps script IDE was changed. :grin:

i opened my app script this morning,.

var imageID = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId(); var imageID2 = DriveApp.getFolderById('1YkETbgeTEcHV2Qhd5QZg0zQXtYi9xcZZ').createFile(blob).getId();

i was changed it last night since new IDE apps script i was wrong to publish it

yes, it work AGAIN, im forget to save the script then deploy. sorry :pray:

Please pray for all of you, our island, Sulawesi Island, Indonesia, another destructive earthquake, the Mamuju earthquake, 6.2 Magnitude. I hope our brothers in Mamuju will be given courage and safety. amin :innocent:

Pleased it works for you, sorry to hear about the earthquake, hope all is well.

1 Like

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