最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Loading a json file into Localstorage - Stack Overflow

matteradmin3PV0评论

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 e 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.

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 e 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.

Share Improve this question asked Apr 10, 2015 at 10:20 kSeudokSeudo 6197 silver badges23 bronze badges 2
  • I don't think its possible to store file in local storage because it will make the client less secure. – Kira Commented Apr 10, 2015 at 10:24
  • You are playing with a JSON file which is on client's machine and localStorage is also a client's browser's storage, client side alone will do it, you don't need to involve any server. – Zee Commented Apr 10, 2015 at 10:26
Add a ment  | 

1 Answer 1

Reset to default 4

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.

Post a comment

comment list (0)

  1. No comments so far