Google Drive Folder of Images and Auto Renaming with a AppScript

So, I have a connected table with a folder on Google Drive that is a set of images. When a user adds an image from a phone, the phone's naming convention breaks the view of the image.

Ex: 12:42:56 - This is what breaks the view in the app

Newly uploaded photo to DriveNewly uploaded photo to Drive

 

 

 

 

 

 

So, I built an Appscript that renames the file in my Google Drive folder, but the bot runs immediately before my record auto-syncs and the _ID passed from the table is different than what is expected.
_ID passed by the bot: 89be46ab
_ID after saved: 1xbMuiGVeEi8MpfTk8BC_uf-wpfJLPOC3

So my question is if there is a way to trigger the bot after the image has been saved to Drive?

0 11 335
11 REPLIES 11

Have you evaluated Wait step in automation bots

Steps: The Essentials - AppSheet Help

 

I have not, but I will look into it. I was looking for something like it but could not find it yet. ๐Ÿ˜Š Thanks!

There isn't anything that signals back to AppSheet that a file has been written.

Maybe inserting a wait condition in the bot but I think the minimum is 5 minutes.   

I believe you could implement something in the script to "watch" the folder and when file appears then rename it.

There is also another possibility you may be able to use to avoid using a bot and a script altogether.  You can pull in a Google folder as a table into your app.  Then add virtual columns to "attach" the file to some data row OR add additional details to the file row such as the user friendly name.  As files are added to the folder they will automatically be pushed into the app.  You can even delete within the app and the files will be removed from the folder.

Check out this article


@WillowMobileSys wrote:

You can pull in a Google folder as a table into your app. 


That is what I have done and why there is the issue. The temporary ID that Appsheet uses does not match what is returned from Drive after the file is written, therefore the bot is using the incorrect ID. Also, the problem is still how some mobile devices are naming the file and why I need to do this.

Thank you for your suggestions. 

What you are saying doesn't make sense.  Could you show examples of the issues you are facing?  We can probably help you sort them out then.

Not sure what does not make sense. I provided an example in the initial post of the root cause. Here is more detail to the same result.

It is a google drive folder table that points to a folder of images. 

BlazeDJr_3-1666310968252.png

Upload:

BlazeDJr_0-1666309789703.png

Uploaded File in Google Drive Folder from App has added timestamp in the name:

BlazeDJr_1-1666310561470.png
Expected _ID of the file to pass to the Bot that calls my script:

BlazeDJr_4-1666311412179.png

This is the log of the data passed to my script:

 

 

Attempt to rename for folder 1.0 and file ID: 5c96a4c3

 

 

The file ID is what my app passes the script when the bot triggers based on an Add Only for the image table. 

 

 

BlazeDJr_5-1666311898775.png

BlazeDJr_0-1666359484818.png

 

That's all it does. The ID passed to my script is not the same id that ends up in the table because I assume it is a temporary ID created by AppSheet until the file is actually saved to the folder and read back. 

 



 

[_ID] is actually the  Google unique ID for the file.  However, the ID for the Path is not provided in the table

I haven't used the renameFile() function, which would be a Google script side function, so I am not certain what "folderID" and "fileID" accept as arguments 

I would try using the text based version of the Path as the "folderID" argument and pass [_ID] as the "fileID" argument.

But, as I think about it, your table will be based on a single folder.  So you could simply hard code the "folderID" argument to be the Google assigned ID and it should never need to change.

Example of Folder ID

".../drive/folders/1GpkYyH6eDarkUO4TDxgX0dTJHsvI96xQ?usp=sharing"

Example of File ID - this is the [_ID] value assigned in my AppSheet table

".../file/d/1GbSNcGXfs-d7413H9IRmmnunCE_fnRtI/view?usp=sharing"

I do have the hardcoded in my script. I created an object that points to a few different folders that the script maintains and the bot task references by a number. I do it for security purposes. I may look at passing the folder path as an alternative and see if that makes a difference. I will let you know. Thanks!

folderID = 1, as shown in your image, is assigning the value of "1".  I don't think that is what you intended. 

And that is not what I mean by "hard coded".

Place the actual ID values into the fields as arguments - no expressions or columns - to verify it works at all.  Once you are convinced it does indeed work, then use a sophisticated implementation that suits your needs. 

Otherwise, you could spend hours trying to figure out why things in your implementation are not working only to realize that the function is not supported or works in a way you didn't understand.

This might help. The first image here is on my folderModel object. It has a class I created to obfuscate passing my personal Google Drive Folder IDs through the app. I use an integer that the app is aware of in replacement.

BlazeDJr_0-1666468726608.png

This is the function called to rename the file in the GoogleDrive script. Nothing abnormally done here.

BlazeDJr_1-1666468911220.png

I hope that makes more sense on what I was doing initially and I always intended to pass the integer for a folder id. Now as I attempt to try a different approach with the folder path, I will let you know if I have better success finding the file based on content from it like the file name. Hope this helps clear the confusion. ๐Ÿ™‚

My original thought is still that it is all about timing. Once I click the save button for the upload, the bot finishes before Google Drive has written the file to disc and returned it's custom _ID that I really needed.

 

Now 


@WillowMobileSys wrote:

But, as I think about it, your table will be based on a single folder.  So you could simply hard code the "folderID" argument to be the Google assigned ID and it should never need to change.


 

Now I better understand your thought process and this will help if you understood my app. Technically it is a grocery list app with optional choices for different stores. Each store has it's own optional Google Drive Image folder for ease of separation. This gives me the reason to have more than one folder as an option for my parameters to the script.

Top Labels in this Space