Does the JSON file upload to the server?

I am creating a GAE application that basically allows the user to select a JSON file on the computer, this JSON file will be slightly modified (i.e. several inserted fields) and will be uploaded to the server for storage in the database.

I am modifying a JSON file locally using Javascript.

My question is that you cannot load and modify JSON (and other resources) from the local machine, does this mean that I must first upload the immutable JSON to the server?

i.e. I have to do it:

1) The user selects the raw JSON file from his computer

2) Then it is uploaded to the server
3) Unchanged JSON is then sent back to the client
4) Run some javascript wizardry in JSON to add new fields, etc. I want to. 5) Upload the modified JSON file to the database
6) Delete the old immutable JSON file from the database

Will this be the right method? It seems pretty long.

Thanks for helping people :)

+3
source share
1 answer

If the user's browser does not support the file APIs , I think your steps might be the best solution. However, many modern browsers support the API, so you can use it.

The bottom line is to create a new FileReader object and load it. When this is done, you will be able to evaluate JSON (using JSON.parse ), making your changes, and then do your loading.

More details here: http://www.html5rocks.com/en/tutorials/file/dndfiles/

Here's a demo using images: http://html5demos.com/file-api

Of course, if it is possible to process the server side instead of the client side, the situation becomes quite trivial.

+2
source

All Articles