Is it possible to download a file or image from Appsheet?
YES!
I wanted to download the file or image with just one click, once I upload a file I sometimes needed to download it for some reason. I was thinking how to do it, and I constantly thought it was impossible.
See the result I was able to get:

How did I do that?
Well I needed to create an automation with an Apps Script code.
I tried hard until I got this result.
You will first need a column in your sheet, I called it Link, and here’s the code I made:
// This function assumes that the information in column B named Photo is in the sheet with the ID 1IKMTjV7o6BTkTUe5ePFN2NoC-5D63AKmx8qzML6mw8o
function getImageId() {
// Get the sheet by its ID and the data from column B
var spreadsheet = SpreadsheetApp.openById(“Your_Sheet_ID”);
var sheet = spreadsheet.getActiveSheet();
var data = sheet.getRange(“B:B”).getValues();
// Check if column C exists and if it has the name link
var columnC = sheet.getRange(“C:C”);
if (columnC) {
var columnName = columnC.getCell(1, 1).getValue();
if (columnName != “link”) {
// If column C does not have the name link, rename it
columnC.getCell(1, 1).setValue(“link”);
}
} else {
// If column C does not exist, create it and give it the name link
sheet.insertColumnAfter(2);
sheet.getRange(1, 3).setValue(“link”);
}
// Loop through each cell in column B and get the image id corresponding
for (var i = 1; i < data.length; i++) {
var fileInfo = data[i][0]; // Get the file information from the current cell
if (fileInfo) { // Check if the file information is not empty
var fileName = fileInfo.split(“/”)[1]; // Get the file name from the information
var folderId = “Your_Fold_ID”; // Get the id of the folder where the images are stored
var folder = DriveApp.getFolderById(folderId); // Get the folder by its id
var files = folder.getFilesByName(fileName); // Get the files with the same name as the file in the folder
if (files.hasNext()) { // Check if there is at least one file with the same name
var file = files.next(); // Get the first file with the same name
var fileId = file.getId(); // Get the file id
sheet.getRange(i + 1, 3).setValue(fileId); // Write the id in column C
}
}
}
}
*PS:*You’ll need to have the image file in column B called Foto and Column C called link to receive the ID of the image. If you need you can change the code to your needs. Replace the Sheet ID and the Folder ID in the code in order to make it older.
After that I create an automation as the image below:
Then…
Create an action to GO TO A WEBSITE and use the following formula:
“https://drive.google.com/uc?export=download&id=” & [Link]
[Link] receives the ID of the file in google drive
The final result is:
Destop: With this link it will automatically download the file/image in the desktop mode (in some PCs it will open a form where you can rename and save the file and others, no! I guess it is some browser setting you can cgange.
Mobile: it will open the file in the drive app in your mobile and then you’ll be to download, share, etc.
But you can also download it instantly in your phone if you unable the “open supported link” in the Drive Application seetings.
Let me know what you think about it, and if it is useful to you somehow.
