Open a file action - get current (not cached) file

While I assume I'm not the first to connect these dots, I don't find this clearly documented anywhere, hence this tip (plus a bit of a background literature review).

There are multiple dense threads from 1-2 years ago regarding how to Open File/Image with external browser without look... - Google Cloud Community, so as to avoid the issue of File column showing cached PDF, not linking to actual file, especially while relying on the important Require Image and File URL Signing security feature that was seemingly implemented in the midst of those discussions.

The solution techniques seem to focus on substituting External: open a file actions with External: go to a website actions using an expression-constructed URL, as well as disabling the Require Image and File URL Signing feature and/or enabling the related Secure PDF/Image access security features that apparently can negatively impact app performance--and seemingly don't address other file types, such as .csv. Another approach mentioned is to ensure every filename is unique, such as by incorporating a timestamp; however, that approach is incompatible with the common use case of using an app to both generate and subsequently retrieve a file.

Although I wasn't optimistic, on a lark I tried @Koichi_Tsuji's technique of adding an arbitrary parameter to an action, but applying it to the open a file action rather than a go to a website action. It worked! My open a file action now reliably opens the current version of the file, including updates made seconds prior, rather than a potentially outdated cached version. My scenario involves .csv files.

For the action's File property, concatenate the filepath/filename string with an ampersand and probably any text--potentially even hardcoded rather than dynamic.

[File] & "&" & UNIQUEID()

Example screenshot:

dbaum_0-1660423914388.png

 

25 20 2,464
20 REPLIES 20

This worked great. Thank you

...Thank you so very, very much for this... now I'm off to delete all the Revision # crap I've been appending to all my documents I need to retrieve.

Can you explain more clearly cause I'm struggling from 10 months ago with error 404 file not found...  this is my formula for open a file "/Manleve/"&[Cliente]&" Manleva "&[Commodity]&".pdf" what should I change??


@Ceke wrote:

error 404 file not found


I think that the technique I described is not relevant to this error.

My technique is for retrieving the most current file rather than a cached version of the file with the same name. In case it's helpful, to apply the technique I described, append any dummy parameter to the end. For example:

"/Manleve/"&[Cliente]&" Manleva "&[Commodity]&".pdf" & "&" & UNIQUEID() 

It is helpfull a lllot for me.. some of the employees opens the file earlier then it was ready and the app gives error 404 after that they struggle to open it even if it was ready... you solved me a great problem man. THANKS!!

I'm glad the technique helped. I guess what might have happened is that the file unavailability error was cached, but using this technique forced a refresh.

The error was cached for almost 30minuts

It does'nt work. Error File Not Found. Some Help

I just tested in one of my apps, and it still works. Also, some of my app users have recently and frequently been invoking this functionality and none have reported any problem.

If your expression without using my technique indeed opens the file but just doesn't reliably open the most recent file version, then I don't know what else to suggest--that's exactly the problem that led to this technique. If you post more details about your scenario, someone in the community may be able to provide advice. For example, explain and post screenshots that illustrate how your file is created and your app's action that is supposed to open the file.

Maybe you've found a scenario with a lurking issue that represents a flaw or gap in the technique I documented. If you are able to isolate whatever I've overlooked, please be sure to post the information for us all to reference.

Hello, my file path is 

Concatenate("AppSheet\Data\Crm-10657836\Files\",[_THISROW].[ID],".pdf")

But how should I add 

& "&" & UNIQUEID() 

??

I've added only the code at the end and it says the file is not found 


@cozyworld wrote:

But how should I add


There are essentially 2 equivalent options: the CONCATENATE function and the text-concatenate operator (&):

Concatenate("AppSheet\Data\Crm-10657836\Files\",[_THISROW].[ID],".pdf") & "&" & UNIQUEID()

Concatenate("AppSheet\Data\Crm-10657836\Files\",[_THISROW].[ID],".pdf", "&", UNIQUEID())

@cozyworld wrote:

I've added only the code at the end and it says the file is not found


If you already tried one of those approaches, then either there's a separate, unrelated issue or this workaround is not applicable in certain unspecified scenarios, as @Ceke may have also encountered.

You could experiment with assigning a (arbitrary) value to the arbitrary parameter and/or substituting a question mark for the ampersand. For example:

...& "&" & UNIQUEID() & "=" & UNIQUEID()

...& "?" & UNIQUEID()

...& "?" & UNIQUEID() & "=" & UNIQUEID()

 Please share your results.

Hello, I have tried this solution but I cannot figure out how to keep appsheet from replacing my '&' with %26 before the file opens.  My action is setup exactly like your image but the link will say "...pdf%26abc..." instead of "...pdf&abc..." which causes a "File not Found" message.  If I manually change the % to a & and hit enter, it forces the reload that I was after, so I have informed my users of this work around, but I would prefer to get this solution working instead.   Does anyone have suggestions for passing an & through to the browser? 

Thank you!

Confirm your expression doesn't have the & embedded within an ENCODEURL function.

Thank you for responding! I am not using the encodeurl function anywhere, though I have experimented with it in various places without success.   I have attached screenshots of my filepath expression and open action function (does not currently have your suffix).  I am on a mac using chrome,maybe there is some local conversion or something? Thank you again for your help!Screenshot 2023-07-25 at 8.40.49 AM.pngScreenshot 2023-07-25 at 8.39.43 AM.png

@dbaum Love this tip!! I've done similar things to prevent SVG images caching, but hadn't thought to apply it here.

I had some issues using just the [filePath] with external URLs, as it would not include the https://appsheet.com/template/gettablefileurl?.. piece. Are you including that upfront in your [filePath]?

This is as close to a reusable action as I could get:

"https://www.appsheet.com/template/gettablefileurl"
  &"?appName="&CONTEXT("AppName")
  &"&tableName="&CONTEXT("Table")
  &"&fileName="&ENCODEURL("file\path\staticFileName_"&[_THISROW]&".pdf")
  &"&"&UNIQUEID()

Jonathon_0-1691523016597.png

 

I"m so glad you may benefit from a tip of mine. You've certainly helped me A LOT!

I've only used the technique with the native Open a file action. So, for example, the value of [File] in the original post is just the filepath that AppSheet needs to append (e.g., folder/filename.csv) to the app's default file storage location. That has worked reliably for me.

As noted in other replies here, others have experienced issues; maybe the approach you devised is a good workaround for others too.


@Jonathon wrote:

similar things to prevent SVG images caching


Great idea!

The method works, but it is necessary to refresh the application. Thanks

I'm having the same problem as KirbyBaylin.  I've set the file path in the field I create to be: 

Concatenate("ResSummaries/",[Job Number],".pdf", "&", UNIQUEID())

I am placing the PDF files generated in the ResSummaries folder.  When I don't include the variable after the PDF in the string, it works great (but uses a cached version of the PDF).  When I add the unique parameter at the end using any of the methods described in the solutions above, I get two issues: 

1) the "&" is converted to "%26" in the URL string in the new browser window that opens.  When I replace %26 in the URL in the browser it works after changing problem #2 (below)

2) the rest of the string seems to create an issue.  I get this message:  

Error retrieving file 'ResSummaries/211.pdf': URL has an invalid signature.

If I delete the remainder of the string (that begins with "&appVersion=" in the URL after the unique ID I created, it then opens the file just fine.  I've tried it with "Open a File" action as well as "Open an External Website" action. 

I am on a Mac using Chrome.  I'm hoping someone can shed light on this.  I'm trying to force the app to open the latest version of the PDFs it creates, not a cached version. 

Thanks for any help!  Wick

 

I figured out what was wrong.  I was adding the unique ID to the path stored in the data field in the table.  It should have gone in the action to open the PDF document instead.  Once I did that, it worked great.  Thanks for the tip!

For some reason it didn't worked at the first try. But then I deleted it and paste it again and now ut works great!

Thank you so much!!!

Top Labels in this Space