How do I upload image to google drive then send link into the google sheet?

Please teach how im beginner please ??

1 Like

Reading ALL of this topic may help you to understand what is involved:

Additional guides:

Also

and also

2 Likes

Hi community, I am new to ai2 app, I have this project for a product inventory application.
I was reviewing some threads, specifically, the mentioned ones and in METRIC RAT AI2 everything available, I tried to use the .aia Jean_Yves_Le_Magnifi and deff_brian creating my own Scripts in Apps Script and modifying the blocks with the links of the macros and the ID of the folders but I didn't get the joke.
1


3
4
5

I'm still using the "com.ghostfox.SimpleBase64.aix" extension to upload the image to drive as it was the first one I learned to use.
The thing is that my goal is to send an image to a drive folder and generate the share link of the same image in a spreadsheet, in the first instance and I was also looking at how to use the cell phone camera to photograph each product from the same app, as I was using an ImagePicker to upload the corresponding image and it is not very practical to be opening the native camera to photograph and then the inventory application to upload the image, there is a way to call my camera and use everything in the same app.

Greetings from Colombia!
CONTROL_DE_INVENTARIO_2_0.aia (22.6 KB)

1 Like

Can you show your google apps script as well ?

Looks like you need to:

  1. Take the Picture
  2. Upload the picture to google drive, and return the File ID
  3. Upload the data to google sheet (with the File ID)

It is possible to do 2. and 3. together with one apps script web app

1 Like
function doPost(e) {
    var ss = SpreadsheetApp.openById('1O8zf1SB5c7zJPCFM37yttMVdpNmImDPBQRdzMrDLt-M');
    var sh = ss.getSheetByName('TIMAI2_demo');
      
     var tag1 = e.parameter.tag1;
     var tag2 = e.parameter.tag2;
     var name = e.parameter.name;
     var mimetype = e.parameter.mimetype;
     var data = e.parameter.data;
     var filename = name + "_" + Utilities.formatDate(new Date(), "GMT+4", "dd-MM-yyyy-HH-mm");
   
     var data = Utilities.base64Decode(data);
     var blob = Utilities.newBlob(data, mimetype, filename);
     var fileID = DriveApp.getFolderById('1KcFjtRmyYG8yb82L8BKI1g8dysOJ8lxA').createFile(blob).getId();
     var file = DriveApp.getFileById(fileID);

     file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);

     var fileUrl = "https://drive.google.com/uc?export=view&id=" + fileID;
   
     sh.appendRow([tag1,tag2,filename,fileUrl])
   
     return ContentService.createTextOutput("Data uploaded");
   
   }
1 Like


It is with this code, isn't it? only that it is specified in the blog that: "(you will need to amend the workings of the Web1.GotText blocks accordingly)"

Done some work for you, created a simple inventory app that take a photo from within the app, then uploads to google drive and sets data to spreadsheet. I used my remix of the procam extension to handle the taking of a photo and converting to base64. All data is saved to google, no data is saved to the device.

BLOCKS

SCRIPT
function doPost(e) {

  var ss = SpreadsheetApp.openById('<YOUR SPREADSHEET ID HERE>');
  var sh = ss.getSheetByName('Sheet1');
  
  var data = Utilities.base64Decode(e.parameters.data);
  var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
  var fileId = DriveApp.getFolderById(e.parameters.folderId).createFile(blob).getId();
  
  var rowData = [];
  rowData.push(e.parameters.itemName[0]);
  rowData.push(e.parameters.itemDescription[0]);
  rowData.push(e.parameters.itemValue[0]);
  rowData.push(e.parameters.filename[0]);
  rowData.push(fileId);
  rowData.push('https://drive.google.com/file/d/' + fileId);
  

  sh.appendRow(rowData);

  return ContentService.createTextOutput('Image: ' + e.parameters.filename + ' with ID: ' + fileId + ' successfully uploaded to Google Drive' );  

}
SHEET

AIA

You will need to add your scriptUrl and your folderId to the blocks
PhotoToGoogleDriveAndSheet.aia (38.0 KB)

4 Likes

Hi, you are just phenomenal, thank you very much, the camera works quite well, just not uploading the information to the spreadsheet, the ID of the spreadsheet has 44 characters right? and in the app I get this error:


It is a Samsung A21s
I used the code like this and gave it Drive API permissions.

function doPost(e) {

  var ss = SpreadsheetApp.openById('1c-l5A-aSeBcsQsDz4YUc6K8XitkTfYyCLmxE4phvGq0');
  var sh = ss.getSheetByName('Sheet1');
  
  var data = Utilities.base64Decode(e.parameters.data);
  var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
  var fileId = DriveApp.getFolderById(e.parameters.folderId).createFile(blob).getId();
  
  var rowData = [];
  rowData.push(e.parameters.itemName[0]);
  rowData.push(e.parameters.itemDescription[0]);
  rowData.push(e.parameters.itemValue[0]);
  rowData.push(e.parameters.filename[0]);
  rowData.push(fileId);
  rowData.push('https://drive.google.com/file/d/' + fileId);
  

  sh.appendRow(rowData);

  return ContentService.createTextOutput('Image: ' + e.parameters.filename + ' with ID: ' + fileId + ' successfully uploaded to Google Drive' );  

}```
1 Like

On your spreadsheet the first sheet is named:

image

The script is looking for Sheet1

Either:
Change the name of the sheet from Hoja 1 to Sheet1 << easiest....
.
or
.

Change this line in the script:

var sh = ss.getSheetByName('Sheet1');

to

var sh = ss.getSheetByName('Hoja 1');

or to use the first sheet on the left

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

Republish the script to a new version, and try again.

3 Likes


Friend, it's working very well, thank you very much. I wanted to ask you how can I create new blocks? so I can call getASD and makeFilename, or how does it work? the same for 'to getASD' and to 'makeFilename'
It has something to do with?: HOWTO: Get Application Specific Directory -ASD (where one exists)
Thank you very much.

You need a File component, then drag out the procedure block and build the procedure. The action block for your procedure will be created in the procedure palette.

1 Like

If you want to get Path to ASD, then you can use this block :

IMG-20220608-WA0008

Help
Exception: Invalid argument: parent.mimeType(line 8, file "Code")

Thank

Something wrong with your google apps script. Post it here, and/or show the full error message that is being returned.

How to create a File Loader Google Web App to Google Drive on Google Sheets:
https://codewithcurt.com/create-file-loader-google-web-app-to-google-drive/

WebViewExtra - Upload/Download Files with webviewer
https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/t/webviewextra-upload-download-files-with-webviewer/76346

1 Like

Thank you

This [paid] extension make your job very easy ↓