Summary
This post describes how to save a clickable link in a Google sheet that will open an image captured through your app. The link created is a Google Drive link, so permissions are based on Google Drive settings. It does not require an anonymously accessible link via AppSheet.
Related topics and limitations
This help article describes how to construct an image url using AppSheet. However, it is only appropriate for non-sensitive content because the links can be accessed anonymously.
This example uses a different approach. When the user adds a record, it triggers an Apps Script function to get the Drive url of the image file and write it back to the sheet
Template and Demo
A few notes:
Description
This a simple example of how to use an Apps Script function to capture the url of a file saved into Drive and write the url back to the app's data source. This supports use cases where people need to access saved photos through the Sheet directly.
Access Permissions
Typically, access permissions for content related to AppSheet apps are controlled through AppSheet. This use case is a bit different. Users are accessing these links directly in the Google sheet rather than through AppSheet. Therefore, access permissions are controlled through Drive. One way to manage this is to grant access to the parent folder of the images. Then anyone with that permission could click any link in the Google sheet and open the image.
In case it's relevant or otherwise of interest to anyone: It's also possible to use Apps Script to set the user permissions for a folder or file in Drive. I've found this handy for managing permissions for files that are needed by the users of an AppSheet app but that are not accessed via AppSheet.
same error.
This is a straightforward solution that works best for processing video, even better than the conventional methods we all know. I have been looking for this solution for quite a while. Thank you @derekco
hi, is it working for you? if yes, please share the script, i am getting an error.
This is my script:
function main(filename) {
var files = DriveApp.getFilesByName(filename);
if (files.hasNext()) {
var file = files.next();
var fileURL = file.getUrl();
// Get the folder containing the file
var folder = file.getParents().next();
// Set sharing permission to anyone can view
folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
return fileURL;
} else {
throw new Error("File not found: " + filename);
}
}
In my case, I set the sharing parameters so anyone can see the file, but you can modify the permissions depending on your needs.
It is important to properly set the filename function parameter, which will vary depending on the folder path where the file is stored. If that's not set correctly, the script will run, but you won't get the return of the URL.
Consider the following example:
This is my folder path where the file is stored: Purchases_Files/6e3ff2f6.FILE.172426.pdf
This is my function parameter: INDEX(SPLIT([FILE], "/"), 2)
The purpose of the function is to extract the file name "6e3ff2f6.FILE.172426.pdf" from the full file path "Purchases_Files/6e3ff2f6.FILE.172426.pdf"
If your file is stored in a path with more subfolders, you should modify the number 2, as that part of the function takes the nth element of the array produced by the SPLIT function.
Hope this helps.
Hi, It works!. been out. thank you very much.
Glad you made it!