How can I use HTML5 local storage to save a little exe file and then download it by clicking the button?
Asked
Active
Viewed 7,275 times
2 Answers
1
Localstorage
as you think is not a DataBase or even the File System, it's just some plain JSON
files that store tiny bits of data in key: value
pairs.
If you have worked with JSON before this will be very easy to grasp the Idea behind it.
Below is an example of setting and retrieving values from Local-storage
:
locastorage.setItem('KEY',JSON.stringify('VALUE'));
// KEY is kind of like the variable name and the VALUE is the actual Data
JSON.parse(locastorage.getItem('KEY'));
// You use the KEY to access the value
// Using JSON methods stringify and parse just to be on the safer side.
0
HTML5 Localstorage is not for files.
Have a look at Mozilla's documentation here: https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
Instead it's for key/value pairs.
// Save data to the current local store
localStorage.setItem("username", "John");
// Access some stored data
alert( "username = " + localStorage.getItem("username"));
To start a download, you may want to look at a question like Download File Using Javascript/jQuery
-
1But what about this link: https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/ It says that you actually can save any file as blob. – Mikhail Apr 24 '15 at 08:33
-
why would you want to do that? and just to be clear, those files are not accessible to the user - they are stored by the browser in a database file. – jcuenod Apr 24 '15 at 19:24