Sending a Picture and location data to googlesheet - using a solution by TimAI2 found on old forum

Hi - am a newbie. Tried some tutorials and made basic app. I saw this solution by TimAi2 https://groups.google.com/forum/#!topic/mitappinventortest/liWppNXqHXM and am trying to replicate his solution.
The App basically takes a picture and the Geolocation and sends data to a googlesheet. The App part works fine, the picture is taken, the coordinates are shown on the APP but when uploading getting an error. It seems the error must be in googlescript.

I copied the script (below) exactly. I made the google drive folder shared and accessible by anyone.
I changed the Folder ID to the images folder.
I also tried sending just the location data without the image.

In the MIT App I changed the googlescript location - this is clearly working as the Googlescript is being executed.
The googlesheet is itself shared with anyone on the web. There is only one tab Sheet1

What am I doing wrong?
Raj

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

function doPost(e) {
  if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat) {
    return message("Error: Please Try Again");
  } 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 imageID = DriveApp.getFolderById('1wolWAcF6_3YUNFRq75GAsZ7Y1Bk0Ttdf').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 viewurl = "https://drive.google.com/uc?export=view&id=" + imageID;
      
      var ss = SpreadsheetApp.getActive();
      var sh = ss.getSheets()[0];
      sh.appendRow([lat,lon,add,imageID,name,viewurl]);
      return message("Success: Image Uploaded and Data Saved");
    } else {
      return message("Error: Please Try Again");
    }
  }
}

function message(msg) {
  return ContentService.createTextOutput(msg);
}[upload_CameraImage_Location_Data_GD (1).aia|attachment](upload://oErojmrAKBfakPNN0cp0q33sX1O.aia) (36.4 KB)

Is the google apps script web app bound to the spreadsheet, or did you create a standalone script?

I have tested my demo script and app and that still works OK

Hi Tim - I created it by going into Tools menu of the Google sheet for the data - So I think its Bound.
When I paste the https://script.google.com/macros/s/AKfycbyInbd5Day7uqxGWwLbu0sr_UVGHKk53C3dDwSmYoxbiEU_Rejj/exec
link in Browser, I am getting the error message in doGet

function doGet(e) {
return message(“Error: in googlesheet first Please Try Again”);

Raj

Yes you will, because the script is set to only work with doPost(e) - so you have to run it from the app or test with “Postman”.You would also need to be adding all the parameters to the end of the url.

What response content are you getting from the app? (You can edit all the error messages in the script so that you know which one is which - but don’t forget to republish the web app to a new version)

Hi Tim - thanks. Yes I did that already. I edited the error messages slighly - so can tell which one.
When I run the app on the mobile - takes the pic. shows the location and upload button.

when I press the Upload button - quite quickly get the Error Message in App Inventor -Error:Pleas TRy Again - in Red -

so the error msg is from the App rather than the script. I checked no data or image saved.

Are your script settings like this:

Have you re-published the scrtip to a new version and reviewed permissions ?

Also, change your web1.gottext to look like this:

1 Like

deleted as issue found

Sorry - ignore - I was being stupid - In Google drive access was not set correctly - and the link was missing a digit. For anyone else - Access needs to be “Any one on Internet can find and edit”.
Thanks Tim for your help and patience.

If the script is running as “you” (your google account) and “you” also own the spreadsheet and the folder, the google drive/sheet access permissions can be tighter - even “private only me”. Try it.

que tal TimAI2
gracias a tus conocimientos e podido desarrollar aplicaciones con Spreadsheet de Google

el tema del mensaje es que las fotos cuando envio a google drive sale 45 grados en su carpero y tambien en la file del Spreadsheet de Google

y no se porque sale eso

te mando el acceso de las carpetas
la carpeta de Google Drive :

y del Spreadsheet de Google y del Google Apps Script :

https://drive.google.com/drive/folders/1iX7Pbqr69u4rCXSdy7aQIit2ue-WzULY?usp=sharing

sip.aia (31.9 KB)

Gracias por tu futura respuesta

hola timAl2
me podrĂ­as ayudar cual es el error

saludos cordiales

You will need to assess the image taken on the camera: is it landscape or portrait, resolve this, then upload to google drive. Try using Taifun’s Image extension.

Si se utizo esa extension el tema esta es que el error esta que el app de camara que viene por defecto lo toma la foto y te da como resultado inclidado a la izquierda.
Estoy utilizando el app Line Camara que puse por establecido para que tome las foto y si se muestra

Your blocks show using the app Inventor camera component?

I do not know how the line camera app works, but the Image extension (or the Metadata extension) may be able to help you.

gracias TImAI2

como se muestra en la imagen yo descarge el aia de metadatos y tomate una foto con mi celular de marca LG Q60 y me sale ese mismo error

orientation right side,top (rotate 90 cw)

As you have seen, different devices give back different information, and handle their camera images in different ways. It would also be difficult to programmatically set the orientation correctly with a square image. You may have to present a preview to your user in the app, leaving it for them to decide if rotation is required, prior to uploading to google drive, if you can figure out which ones will be rotated on google drive. (Some devices return the image rotated 180 degrees!

Que tal. TImAI2. Te comento que comencé a tomar foto a la orientación hacia la izquierda de la y si me guarda a la orientación correcta en el google drive

Una consulta cuanto seria la medida necesaria
Para el tema del maxwidth y el maxheight

Please explain the issue you need to resolve in more detail. I do not understand what your problem is…

Me referia al tamaño de la imagen porque cuando la imagen es mas grande el aplicativo demora en el proceso de enviar los datos y cuando la imagen es pequeña se pierde la resolución
Para el tema de la imagen el tamaño en el maxwidth y el maxheight
Cual seria el recomendable.

Maxwidth :600
Maxheigth: 400
Aumentar las unidades de medida
Y si es asi cuanto seria lo recomendable
Saludos