HOW TO: Get Google Drive Image ID by Using Its Name in an App

694 views
Skip to first unread message

Techno Peace

unread,
Jun 14, 2019, 1:43:01 PM6/14/19
to MIT App Inventor Forum
Hello, I want to get an image ID when I only know the name of the image. Thanks for your time. 

TimAI2

unread,
Jun 14, 2019, 2:36:30 PM6/14/19
to MIT App Inventor Forum
You will need to store the filenames and file IDs in a google sheet or other database, then use this to access the file

See here which handles the image ID / filename and location !!

Techno Peace

unread,
Jun 14, 2019, 6:46:37 PM6/14/19
to MIT App Inventor Forum
I meant ID by ID of image sent before to Google Drive there in url bar like "1ZF9G9V75B46_5K8R7xVONMgy0tHXlXy".

Techno Peace

unread,
Jun 14, 2019, 6:53:22 PM6/14/19
to MIT App Inventor Forum
How to get it. Straightly I want to get image back I sent before with name by using its name not its ID. Briefly how can I display and delete a photo in Google Drive by using its name not its ID. (I know how to do that by using its ID but I want to do that by using its name which is in Google Drive)

TimAI2

unread,
Jun 14, 2019, 7:16:35 PM6/14/19
to MIT App Inventor Forum
If you do not know the File ID of the file on Google Drive, but you know the name of the file, you will need to use a google apps script to carry out the search.

One of the problems with this method is that you can have many files with the same name (and therefore you could call or delete the wrong file), but they will all have different FILE ID's, which is why you should write your code with both (and much easier to call the ID)

Here is an example of such a script:

I would still refer you to my previous post above, that if all images are originating from the app, you can capture the filename and file ID when you upload them to google drive, either back to the app or to a google sheet, then using lists of pairs to select a filename but actually use it's ID to carry out action on the file.

Techno Peace

unread,
Jun 14, 2019, 7:45:33 PM6/14/19
to MIT App Inventor Forum
The apps script seems including the text searching. But the texts can be changed in my app. How can I change the text writen on the script later?

TimAI2

unread,
Jun 14, 2019, 7:54:45 PM6/14/19
to MIT App Inventor Forum
Create a web app that requires parameters, send these from the app using the web component

Techno Peace

unread,
Jun 14, 2019, 8:00:14 PM6/14/19
to MIT App Inventor Forum
Sorry, I'm new on web app , could you give me some examples that web app gets argument parameters(inputs) and (if It is imposible) outputs.

Techno Peace

unread,
Jun 14, 2019, 8:03:28 PM6/14/19
to MIT App Inventor Forum
I've meant "(If it is possible)" , sorry.

TimAI2

unread,
Jun 15, 2019, 4:57:13 AM6/15/19
to MIT App Inventor Forum
The example I linked to previously shows the workflow to upload an image and to set the image information to a spreadsheet
To get it back to the app follow this tutorial:

In its simplest form:

function doGet() {
var ss = SpreadsheetApp.openById('ENTER YOUR SPREADSHEET ID HERE');
var sh = ss.getSheets()[0]; //if you keep your sheet tabs in the same place, you can select any sheet tab
var rg = sh.getDataRange().getValues(); //fetches all the data values on the sheet tab

var outString = '';
  for(var row=0 ; row<rg.length ; ++row){
    outString += rg[row].join(',') + ';\n';  //this section adds line returns to the rows in your data
  }
return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);  //returns the data to the app
}


The script can be bound to the spreadsheet or standalone

You also want to delete images on google drive by filename. Manipulate the data you have called down from the sheet in the app to find the file id from the filename, and then use this



Techno Peace

unread,
Jun 15, 2019, 7:05:42 AM6/15/19
to MIT App Inventor Forum
Can I use Firebase to store text instead of spreadsheet here? And I have to say that I didn't understand how to change the text I search in Google script code.

TimAI2

unread,
Jun 15, 2019, 1:22:40 PM6/15/19
to MIT App Inventor Forum
Yes, you can use firebase but image storage is a bit flaky and you will need an extension to do it. Do you know how to use Firebase ?

I may get a chance later to have a look at a search script for you....

Techno Peace

unread,
Jun 15, 2019, 1:57:10 PM6/15/19
to MIT App Inventor Forum
I plan that I use Firebase as a text recorder. I would use Google Drive as Image recorder. I know Firebase goes error when recording image. Thanks for your help. 
Reply all
Reply to author
Forward
0 new messages