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.
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
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)
BLOCKS
SCREEN (after running "Fetch")
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 :)