How to store large files to web local storage?

2019-02-25 06:27发布

I am developing ionic 2 app that downloads files from online servers, I want to store those files to the local storage (or caches I don't know).

I know that I can store data to local storage using:

localStorage.setItem('key','value');

But if it is file and specially a large one, how to store it in local storage?

Note: I am using TypeScript.

2条回答
聊天终结者
2楼-- · 2019-02-25 06:34

For storing relatively large data, I'd recommend using IndexedDB.

Advantages over local storage:

  • Larger size limits
  • Supports other data types than string (native typed arrays!)
  • Asynchronous
查看更多
看我几分像从前
3楼-- · 2019-02-25 06:39

Browsers have limitation on how much data you can store in local storage. It varies from browser to browser.

If your file size is under the limit, you could copy the file content as a string and save it as a key value pair of "filename":"file content"

查看更多
登录 后发表回答