Good day, all. Is there any way for Anvil to easily access a non-temporary URL for Google Drive files which are configured (in Google Drive) so that “Anyone on the internet with this link can view” ?
I have several hundred files in a Google Drive folder, and I’d like to cache their URLs so that I don’t have to query the folder contents each time. Right now, the only way I can see of getting a link to the file is via .url attribute, which as far as I can tell generates a link that is only valid for the current session.
Is my best bet to use Google’s own APIs? Or is there some way I can address this via Anvil’s APIs?
If you use introspection you’ll find that each google object has a _obj attribute. This is a private attribute. But you’ll find some useful properties there.
Typically you can grab the id from here and then infer the share url based on that value.
I played around a bit with the ._obj method and found that, if the Google Drive is set for link access (“Anyone with the Link can view”), then this gives an accessible URL for accessing a file stored via the sequence below. Note the folder name is the App File created in the Google API service with a folder selected.
folder = app_files.<your_folder_name>
file = folder.create_file("Name of file", media object)
url = file._obj["alternateLink"]
I have a bottom level folder (a ‘leaf’) with permissions set to provide universal access. I then put temporary files there for use in subsequent workflow modules invoked from my Anvil.Works app. Works very well.