Amplify-ios: Question Datastore: Best practice to store static files

Created on 2 Nov 2020  路  3Comments  路  Source: aws-amplify/amplify-ios

We are using Datastore inside our app to get offline capability, which works really well.
Now we want to implement possibilities to capture images offline and upload it to the cloud, when a valid connection is established.
My suggestion is to store images on the local disc and listen to the Amplify.Hub to trigger some kind of upload function, when the hub invokes syncing. Is there maybe a better approach or even a best practice?

datastore question

All 3 comments

If you're uploading files to the cloud, you'll want to investigate Amplify Storage. You can listen to the Amplify Hub events and then trigger appropriate Storage operations when the sync starts. We're working on a PR that will better explain the Hub Events so you can find the right one for your needs--my initial thought is that you'd want to listen for syncQueriesReady to ensure that all your model changes are up to date locally.

As far as best practices go: since we don't support Complex Objects in DataStore, it's really up to you how you want to reference the objects to the DataStore record. At a bare minimum, you'll need something by which you can derive the object's key, and you'll need to make sure your app uploads the object with appropriate access levels (protected, private, public) for your use case. Make sure you know how you want to handle error cases and consistency as well: e.g., should you wait to fire a mutation until the upload succeeds? Should a data model be changed to reflect a new status if the upload fails? Or are the objects and models loosely coupled enough that they don't need to be synchronized?

Hope this helps.

Hi @palpatim ,
Thank you for your answer. Is this topic on your roadmap to support static files with offline capabilities as well?

Hi @palpatim ,
Thank you for your answer. Is this topic on your roadmap to support static files with offline capabilities as well?

It is, we don't have an ETA yet but we're actively evaluating that feature. This issue is related to the same feature request https://github.com/aws-amplify/amplify-ios/issues/799

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kilo-Loco picture Kilo-Loco  路  6Comments

Jun711 picture Jun711  路  5Comments

sebsto picture sebsto  路  8Comments

DanielZanchi picture DanielZanchi  路  5Comments

petermauger picture petermauger  路  3Comments