Offline Mode S3 Upload Data

Hello!

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

3 Likes

Upon further investigation it looks like the file does get "uploaded" to S3 but it's an empty file.

Hi @Charles_Bisbee,

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