I could read in the Chrome storage API page that we can store string values inside Chrome storage against keys. Is there any way to store files against keys inside Chrome storage?

- 31,849
- 12
- 86
- 121

- 55
- 6
-
1Chrome storage follows the same standards as the localStorage API therefore you should review this question which has already been answered https://stackoverflow.com/q/4940586 – davidcondrey Jun 05 '17 at 07:09
-
Thanks for the link. LocalStorage has limited space compared to the Chrome storage. Is it good idea to store base64 encoded file strings in Chrome storage against keys. The number of files would be in Thousands and the total amount of space may exceed 5 GB. The above link mentioned by you suggests to use File APIs which I believe is the right path if what I suggested above is not a good idea. – user3191524 Jun 05 '17 at 07:33
-
File API would be order(s) of magnitude faster since it doesn't convert files to strings. – wOxxOm Jun 05 '17 at 13:11
1 Answers
chrome.storage
stores data as the JSON stringification of the values which it's given to store. So, yes, if you convert your file(s) into a form that can be converted to JSON (e.g. by JSON.stringify()
), then the contents of the file can be stored. If the value that you are trying to store in chrome.storage
can not be converted to JSON, then it can't be stored (e.g. DOM elements). chrome.storage
does not inherently care what the data represents, only that it can be JSON stringified.
If you're asking, as stated in your comment, if it's a good idea to store thousands of different "files" totaling more than 5GB in chrome.storage
, then the answer is: "NO!".
If you are looking for alternatives, then some are provided in Can you use HTML5 local storage to store a file? If not, how?

- 31,849
- 12
- 86
- 121
-
2But in chrome storage we could store unlimited data by setting the property "unlimitedStorage" in the manifest of chrome extension https://developer.chrome.com/apps/declare_permissions#unlimitedStorage So why would you believe having 5 GB of data in Chrome Storage a bad idea? Could you please explain? And regarding the storing of files in Chrome storage; I am able store them as blob or bufferdata format, rather than json; So I believe it should be fine to get the blob back from chrome storage, and somehow converting blob to file again. Please let me know if its not a good idea? – user3191524 Jun 06 '17 at 15:10
-
Chrome converts to JSON, period. You don't have to convert to JSON yourself, they just need to be *able* to be converted to JSON, because Chrome does convert them to JSON. – Makyen Jun 06 '17 at 15:12
-
If you are really interested in why, then that should be [another question](https://stackoverflow.com/questions/ask), because any answer beyond "performance" starts to get too long for comments. – Makyen Jun 06 '17 at 15:16