Reputation: 53
my goal is to upload an image and some extra data in json/xml from javascript/jquery. Since I am currently developing using the PhoneGap framework, this seems to be a bit of an hassle. It does not seem to be a problem doing this separately, but then I kind of loose the relation between the image, and the data that is describing it.
Does anyone have ideas of how to do this? Or some other nice way to "keep the data together"?
Thank you for any suggestions, OMA
Upvotes: 2
Views: 2014
Reputation: 7655
If u are using Phonegap, you should use the Filetransfer API of it.
You could do it like this and send your json object too.
var options = new FileUploadOptions();
options.fileKey="document";
options.params={};
options.params.fileName = options.fileName ;
options.chunkedMode = true;
options.params.documentDio=dio;//THIS IS YOUR JSON OBJECT
var ft = new FileTransfer();
ft.upload(fileURI, uploadUrl, function(data){
//callback
}, errorFn, options);
Upvotes: 2
Reputation: 829
It could also be worth checking out the Jquery Form Plugin, this catches the form submit in js and allows you to do whatever with the data before sending it to the server. It works with file uploads too, it uses an iframe approach similar to jperovic's suggestion except that it does it all for you. It's worked well for me in the past.
Upvotes: 1
Reputation: 20191
You should check out the jQuery IFrame plugin:
http://softwareas.com/jquery-iframe-plugin
AJAX communication does not allow multipart data so, the the only two ways I know of are to
Hope this helps...
Upvotes: 1