I have a mobile app that is offline enabled and I have a use case where a JS query is called and iterates through an array of images to upload and for each one it then triggers another S3 Resource query which actually uploads the data. Both the top-level JS query and the S3 Resource query are marked with Offline Type as "Write".
The behavior that I am seeing with this setup that is strange is that when the app is offline and the JS query is triggered we are seeing errors from the nested S3 upload calls with the message "unsupported url". Then when the app goes online the pending job is marked as successfully processed but the images never actually get uploaded to S3. I wouldn't expect that the nested S3 upload queries would actually get triggered in the offline use case and if they were then they would not actually attempt to make the upload since its marked Offline Write.
After investigating the app and network logs it that the "Upload Data" action under the hood has a dependency on generating a Pre-signed URL and then it makes a subsequent request to upload the data with that URL. In offline mode this is causing issues because it is attempting and failing to fetch the initial URL even though the app is offline and should skip that step.
I am wondering if at a high level this is a valid approach to take for this use case and if there are any suggestions for better approaches to get this offline S3 image upload use case working? Happy to share more details on the setup!
Thanks for reaching out! Apologies for the delay here.
According to our offline mode docs, and the behavior you're seeing in the app, offline Write queries run sequentially when the connection is restored. It sounds like you are seeing the expected behavior where the queries re-trigger when the user is back online (and then fail due to the JS query dependency).
To clarify, is your preference that the offline triggered queries do not run when the user's network status is restored to online? If so, you should be able to solve your use case by switching the offline handler to type Read
It's a bit counterintuitive since they are actually write/update queries, but this setting only impacts the offline mode. They should still write to s3 successfully when triggered while online.
Let me know if that's not quite the solution you're looking for or if this suggestion doesn't work as described in your app. Happy to take another look
Thank you for looking into the issue and appreciate the detailed explanation.
In our case, we do want to call the query to upload the files to s3 when device goes online. We have a hunch that the issue is with how the s3 resource query behaves under the hood.
When upload / put action is triggered, it looks like s3 resource query under the hood
makes a request to get a pre-signed url to upload the file (empty file being placeholder for the content to be uploaded created with pre-signed URL)
once it receives the pre-signed url, it then uses that url to actually upload the content.
that means, there is a dependency between query 1. and query 2. Per documentation, this is not supported on offline mode and all queries called should be independent as when the device goes online, all the queries are run sequentially.
Does this mean that s3 Resource Query is not setup to handle offline mode?
OR
Is our understanding incorrect on the inner working of the S3 resource query?
Thanks for the follow up! Apologies that I misunderstood your use case a bit
As far as S3 offline support, it seems more use case specific. On my side, I was able to use offline mode to successfully upload string data, as well as image blob url data from the image component to a s3 file. I triggered the query when offline, and it successfully completed when back online. You could also leverage the variable workaround suggested here: Retool Offline Mode? Does it work for js queries? - #4 by lindakwoo Ultimately, you need a way to upload to S3 without depending on multiple queries
If you need base64 images, on the other hand, that is a bit trickier. If you're using the image upload component, it'll be split it into two queries (which isn't supported offline) to get the base64 data in a JS query and pass it with additionalScope. It's also tricky to loop through multiple images and upload them to S3 since you'd need a JS query to loop over the images.