Save big amount of data

Hello guys, I want to save big amount of data. The data is a JSON file which allow user to use application offline.

I can’t save it to AsyncStorage because this JSON is more than 6mb. And as I know I can’t increase this param without eject from expo.

I tried to use Expo FileSystem but don’t know how to save. In official doc I didn’t find good example for saving json.

I don’t want use sqlite, because it makes implementation much complicated?

So, do you know how I can save more than 6mb of data?

Thanks.

6 MB of JSON is a lot. I mean, A LOT, especially for one user. I’m guessing some, or possibly a lot, of that data must be binary. Unless maybe you’re downloading an entire book.

Anyway, what I’m getting at is that you may want to store critical data in AsyncStorage with references to big blobs of data in FileSystem. You can save JSON (or any other string) with FileSystem.writeAsStringAsync() (FileSystem - Expo Documentation). If some of that data is indeed binary (like, say, impage base64 embedded in JSON), you can maybe serve that separately and download it directly to disk with FileSystem.downloadAsync() (FileSystem - Expo Documentation).

SQLite is an option, but I’d avoid it unless you really need the benefits of a relational database.

2 Likes

Copy - paste from my code:

To read it:

let queue = await FileSystem.readAsStringAsync(FileSystem.documentDirectory + `offline_queue_stored.json`);
        let data = JSON.parse(queue);
        console.log(`JSON Loaded: ${data.length} array elements saved inside.`);

To write it:

await FileSystem.writeAsStringAsync(FileSystem.documentDirectory + `offline_queue_stored.json`, JSON.stringify(data));

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.