How to download images and files in Appsheet

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:

 

Screen_Recording_20231019_130132_Samsung-Internet.gif

 

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:

peterson_2-1697732487898.png

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.

3 5 1,554
5 REPLIES 5

Looks like this method will no longer work after the change in Drive functionality is completed May 1, 2024. While Drive will no longer allow download links, links to viewing files in Drive would still be possible, so the link could presumably be reformatted to do that using the same getid() script.

Edited to add: 

Went ahead and incorporated the getid() function into one of my workflow scripts and confirmed that I could make a valid link format with the formula "https://drive.google.com/file/d/"&[DriveID]&"/view?usp=drive_link". Mobile use has the identical user experience as above, but Desktop does change from being a one-click operation into the action opening a drive view window and where you can click to download.

After reading about the new functionality of GDRIVE, I am looking for a solution and already have an answer here. Huge thanks!!

Bem Mateus eu olhei o post e ainda não pesquisei uma solução acerca deste assunto, mas vamos aguardar para ver se o google disponibiliza outra forma de fazer tal coisa. 

I am not aware of this update. Could you please send me the link of this?

Top Labels in this Space