localStorage store large size data

為{幸葍}努か 提交于 2019-12-05 08:58:30

You can't! Usual limit is 5 mb.

Some browser such as Opera allow you to adjust the size, but this is purely dependent on browser and is a user initiated action, not a programmable one.

And even if you could, remember that localStorage can only store strings so anything else need to be stringified first. That together with this being an key/value storage array you will run into pretty poor performance at the end.

If you need large storage capacity, look into File API instead. This is made to work with large files (Blobs) and you can store anything as a Blob.

800 Gb is a large size and File API can only work as fast as the file system (at best, more likely a bit slower as it is sandboxed, ie. not a pure file system).

More about File System API (Note: discontinued as of 4/2014):
http://www.w3.org/TR/file-system-api/

Tutorial:
http://www.html5rocks.com/en/tutorials/file/dndfiles/

Blob:
https://developer.mozilla.org/en-US/docs/Web/API/Blob

Update As the Filesystem API has been discontinued there are essentially only two options left (besides from storing data to the server):

  • Indexed Database API aka Indexed DB (recommended)
  • Web SQL (deprecated but still supported in browsers such as Safari)

Also these are initially limited in size by the browser. It is possible to request a larger quote which the user is asked to accept.

See more details about this API here:
http://www.w3.org/TR/IndexedDB/

There is LargeLocalStorage which provides a cross-browser way to storage large amounts of data locally. You can store binary data or strings.

LargeLocalStorage uses the FilesystemAPI on Chrome, IndexedDB in IE and Firefox and WebSQL in Safari.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!