Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a json file into Localstorage

I want to allow my users to select a json file from their file systems and load it into the localstorage of their browser without any request to a server. From here I want to allow the user to do some modification of this JSON via a javascript UI before it is posted off to a REST service later. The main reason I want to persist it in local storage is that they can come back to it at a later date rather than having to select it again and I dont want this JSON saved directly on the server until they are ready.

Is this a scenario that can be achieved purely on the client side with as xmlhttprequest to load the file and localstorage to persist it? Have any of you guys implemented something like this before and if so can you provide some guidance?

Many thanks,

kSeudo.

like image 780
kSeudo Avatar asked Nov 23 '25 00:11

kSeudo


1 Answers

Yes, using the HTML5 files api. User will upload file, you can read it and persist it to localStorage, and make amends before posting it to the server. Have a read of This

Obviously you wouldn't save the actual file, just the parsed JSON object.

like image 104
Joe Fitter Avatar answered Nov 24 '25 15:11

Joe Fitter