Skip to first unread message

TimAI2

unread,
Jan 7, 2019, 7:55:30 PM1/7/19
to mitappinv...@googlegroups.com
##ALERT##
Google now appear to have introduced automated query checks on file downloads for public files. 
This may result in any files downloaded using this process returning as created, but empty.
You may need to consider a different approach:
##end of ALERT##



This howto is a complete rewrite of my original howto based on Taifun's "webprefetch / file by file" approach 
for downloading multiple files to an app on first run.  I have set it up to show it can download files of many / all
types, as opposed to just images, and the work on google sheets now takes place on one sheet with one script
to generate the filenames and file IDs.

The app itself is a demo app, so I have included a "Fetch" button to start the download, and a "Reset" button so
that the process can be run again (resets the "first run" tinydb tag). If run after Reset, the files will be downloaded
again and will overwrite the existing files.

On completion the app displays the foldername and the filenames.  I haven't included any "production"
error checking for this demo.  The google sheet and the files are accessible for anyone to use with the app.

GOOGLE SCRIPT

scriptGDFilesDownload.png


GOOGLE SCRIPT AS TEXT


function getFileIdAndNames() {

 
var FileFolderID = '1Ty8jdfe6TbT-8KDuqPAHYNVdZVAmkyDK'; // the ID of the folder with files
 
var ss = SpreadsheetApp.getActiveSpreadsheet();
 
var sheet = ss.getSheetByName('FileIDsandNames'); // or use 'var sheet = ss.getSheets()[0]';
 
var urlCol = 1;
 
var urlRow = 1;
 
var folder = DriveApp.getFolderById(FileFolderID);
 
var files = folder.getFiles();

 sheet
.clear();

 
while (files.hasNext()) {
 
var file = files.next();
 sheet
.getRange(urlRow, urlCol).setValue(file.getName());
 sheet
.getRange(urlRow, urlCol+1).setValue(file.getId());
 urlRow
= urlRow+1;
 
}
 
}



GOOGLE SHEET (after script has been run)


sheetGDFileDownload.png



BLOCKS


blocksGDFileDownload.png



SCREEN (after running "Fetch")


screenGDFileDownload.png


aia attached :)



Please visit: How to overcome the App Inventor project limit of 10 MB

or: Howto: Using Google Drive to access Files (Images) from AI2

for more information


My thanks to Taifun for the inspiration :)




GDFileDownload.aia

ndrorian

unread,
Jan 9, 2019, 12:59:03 PM1/9/19
to MIT App Inventor Forum
Thank you TimAI2,
I wanted to use your approach to save image files on the device and then display them later. I added Button3 (Picture) and coded the block below. The image files get uploaded but I can't get to display any image. I have tried both .jpeg and .png files. 
I don't know if I am missing something. Please help.

Screen Shot 2019-01-09 at 9.45.34 AM.png



Screen Shot 2019-01-09 at 9.49.48 AM.png




TimAI2

unread,
Jan 9, 2019, 3:07:43 PM1/9/19
to MIT App Inventor Forum
Remove the <img src="  and no doubt the "/> from the first line of your join block

You do not need these html tags, just the path to the file

ndrorian

unread,
Jan 9, 2019, 4:23:38 PM1/9/19
to MIT App Inventor Forum
I removed the tags but still I don't get any images displayed. I have attached my .aia file to this post.

Here is my Sheet in Google drive. Thanks.

TD AntiPasto Salad.jpg16hFiP9hTEkXYl3oeJ_UW7Gu1l6TbimQ7
TD BBQ Chicken Sub.jpg1Ial32ZWF4oN9gAd8oChEh_GB2YdymBsx
TD Cajun turkey.jpg1_fmbTlGt1R6PVQO-vf1mnbJ_Gnr3MyUL
TD AntiPasto Salad.png1cTE8rDamDwyarQYcwEA1xFZvnYhzOf3Ff9okW6ARkO0
TD Minestrone Soup.png1h8ADW4B2CKht3fEWdN5TeoKyCHWSLe45ayOGffEBnm4
TD Salad.png1orq3mzuZyO9O3lcTEaIMS-HF1T3dL-1YV-Ci1L9v1Cc
GDFileDownload_mine.aia

TimAI2

unread,
Jan 9, 2019, 5:04:10 PM1/9/19
to MIT App Inventor Forum
Three of your image files in the list are actually Google Drawings, so they will not download (just as Google Docs, Google Sheets or Google Slides will not download) hence why you are only getting some header info back.

The Cajun Turkey Roll is an odd one, downloads but in greyscale ? Don't know about that?

The other two were OK

Some work on your images, perhaps.

Also keep your google sheet outside of the "files" folder.

Change the download url back to include the gid, even if it is 0, then next time, you don't have to remember how to do it!

csvurl.png


apprendre l'arabe

unread,
Dec 17, 2019, 9:09:28 AM12/17/19
to MIT App Inventor Forum

q1.PNG

Hi !
Thank you for your tutoriel.
where to find what to put here ?:

q1.PNG

TimAI2

unread,
Dec 17, 2019, 9:52:07 AM12/17/19
to MIT App Inventor Forum
Please explain what your issue is? If you want the folder ID, open the folder in Google Drive and look in the url address bar, you will see this and you want the highlighted part:

https://drive.google.com/drive/folders/0G5al230KXbSyUWJkVzloZ2pOVWM

However, if I remember correctly these blocks are not needed for the activity!

apprendre l'arabe

unread,
Dec 19, 2019, 4:14:22 AM12/19/19
to MIT App Inventor Forum
thank you. I just loaded the .aia you gave us and try to run it
i will delete it and see
thank you for your help

apprendre l'arabe

unread,
Dec 19, 2019, 7:18:20 AM12/19/19
to MIT App Inventor Forum
Hi
I have added write permission (i am working on kodular)
When i click on the first button, ask for permission appear, i accept -> ok
When i click on button 3, the app load images from google drive / csv and load it into file -> when i check on my phone the file appeared and the images are inside
when i click on button 2, normally 3 images have to appear.. But they don't...

c1.PNG


What did i miss ?
Thank you a lot


testing.aia

TimAI2

unread,
Dec 19, 2019, 7:30:18 AM12/19/19
to MIT App Inventor Forum
If you are using Kodular, then you should ask your questions on the Kodular forum
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages