In the last post, I just added the entities in the database, but did not bind the meta data with eBook files. This post will demonstrate how to upload the file in AJAX flavor:
The idea is inspired by this tutorial , using dojo.io.iframe, we could submit a form with file upload asynchronously. In client side, a hidden field meta is added to store the marshaled JSON string. dojo.io.iframe.send shares the same defer concept as dojo.xhrPost:
meta.value = dojo.toJson(cache[i]);
// submit the form
In server side, the JSON string needs to be wrapped by textarea, this is the hard requirement of dojo.iframe.send.
Conceptually, add-by-search will issue INSERT operation to the database, the result may fall in the following categories:
- FileAlreadyExist: the eBook file exists, so the uploaded file is discarded
- UnexpectedError: an 500 error happens in server side for unknown reason.
Check r34 for the implementation.