Reputation: 2634
I am building a GAE app that basically lets a user choose a JSON file on there computer, this JSON file will then be changed a little (i.e a few fields inserted) and uploaded to the server for storage in a database.
I am altering the JSON file locally using Javascript.
My question is, since you cannot load and change JSON (and other resources) from a local machine does this mean I have to firstly upload the unaltered JSON to the server?
i.e. do I have to do this:
Would this be the correct method? It seems quite long-winded.
Thanks for your help people :)
Upvotes: 4
Views: 1578
Reputation: 2184
If the user's browser doesn't support the File API, then I think your steps may be the best solution. However, many modern browsers do support the API, so you may be able to make use of it.
The gist is to create a new FileReader
object and load it. When that's done, you should be able to evaluate the JSON (using JSON.parse
), made your edits, and then do your uploading.
Read more here: http://www.html5rocks.com/en/tutorials/file/dndfiles/
Here's a demo using images: http://html5demos.com/file-api
Of course, if it's possible to do the processing server-side instead of client-side, the situation becomes fairly trivial as well.
Upvotes: 3