How to apply a custom file name to multiple images uploaded in the app

The goal

  1. User provides some information in the app
  2. User uploads a photo
  3. AppSheet applies some logic to create a custom filename based on user-provided info

Background

By default, AppSheet includes the key value in the image file name. See the 'Image storage in the cloud' section of this doc for details: https://support.google.com/appsheet/answer/10106529?hl=en#how-image-capture-works
There have been a few posts about how to use the default behavior to create a semi-custom name. This one is really good: https://www.googlecloudcommunity.com/gc/Tips-Tricks/More-User-Friendly-Image-names-for-images-uploa...

But what if we want to fully customize the file name? What if we have multiple photos collected in one table? That's what this post is for.

Resources

How it works

User actions
  1. Add an inspection
  2. Provide your custom file name for photo1 in the 'photo1_id' field
  3. Provide your custom file name for photo2 in the 'photo2_id' field
  4. Click Save
Behind the scenes
  1. When the inspection form is saved, an automation is triggered
  2. The automation sends the user-provided file name and relative file path to Apps Script
  3. Apps Script renames the file and passes the new relative path back to AppSheet
  4. AppSheet updates the relative file path in the data source
Other helpful features
  • Valid_if functions in the column settings for 'photo1_id' and 'photo2_id' ensure the user-provided values are unique. 
  • Require functions on the photo id and photo columns ensure the app has all necessary user input to perform the requested action.

How to copy the app to your account

  1. Copy the app template linked above
  2. Go to script.google.com and create a new project
  3. Copy and paste the apps script function from the GitHub repo linked above
  4. Give your project a useful name (e.g. Image Names) and save
  5. Open your copy of the app and navigate to the Automation page
  6. Click the process step called 'Rename photo1'
  7. Select the Apps Script Project you created above
  8. Authorize the script
  9. Choose the function name 'renameFile'
  10. Save the app
  11. Click the process step called 'Rename photo2'
  12. Select the Apps Script Project you created above (note, it may look like it's already selected, but it you're seeing an error, then re-select it).
  13. Choose the function name 'renameFile'
  14. Save the app

You should now be able to add records to the Inspections table and see the custom file names get applied. Woohoo!

Additional customization

This is a simple example to highlight the integration with Apps Script to customize file names. Feel free to take it as a starting point and customize for your apps.

 

8 6 806
6 REPLIES 6

Thanks for adding the link. I didn't find @JPAlpano's post when I was searching. Yes indeed, exact same idea!

Wait... we need to use a script for this?

Why not a "filename" option just like PDFs?

  • Surely that system could be ported to work for images just as it does for files?  They're the same thing... no?

-------------------------------------------------------------------------------------------------------

Your script is cleaner and more simplified.  Thanks for the tip.

Hi, 

I don't understand why it renames well when we work with a main folder (example "projects"), but it doesn't work in subfolders (example, "projects/subprojects")

Example;

Field [photo1] type image
Value Type Details, Image/File folder path = "projects"
Work fine. Create the directory, rename the image and upload it, everything is ok

Field [photo1] type image
Value Type Details, Image/File folder path = "projects/subprojects"
It does not work, The image is uploaded to the corresponding folder but the file is not renamed with the proposed name

App works on google drive (G.Workspace)
I have also tested with the default app directory (contenido_images/projects/subprojects), unsuccessfully.
I have also tested task boot process "rename photo 1", changing the values โ€‹โ€‹in the filepath of function parameters, without success.

Thanks
Javier

The script provided does not handle subfolders. It assumes that the path is only one-folder long. 

To handle a chain of subfolders you need to have an additional folder processing function in your Apps Script.

Top Labels in this Space