将多个图像上传到api – phonegap

我在一个phonegap项目中,我有一个页面,其中包含一些内容发布到服务器。 我已将文本内容发布到服务器,如下所示“

$.ajax({ url:"http://xxxx.xxx.xx/mobapp/api/save-data", type:"POST", crossDomain: true, dataType:"json", data: {pliid: document.pliform.pliid.value,idate:document.pliform.date.value, snum:document.pliform.street_no.value, sname:document.pliform.street_name.value,state:document.pliform.state.value, pcode:document.pliform.PostCode.value, suburb:document.pliform.Suburb.value, productlist:pl}, success: function(data) { alert("success"); console.log(JSON.stringify(data)); }, error: function(jqXHR, textStatus, errorThrown,data) { console.log("readyState: " + jqXHR.readyState); } 

一切正常,但我想上传一些从设备上拍摄的图像,我没有任何关于上传多个图像的想法,因为我没有太多的经验将文件上传到api。 等你帮忙。 谢谢。

使用phonegap上传图片

  function uploadImage(){ //Using Camera navigator.camera.getPicture(uploadPhoto, onFailcapturePhoto, { quality: 50,destinationType: Camera.DestinationType.FILE_URI }); //Using library navigator.camera.getPicture(uploadPhoto, onFailcapturePhoto, { quality: 50,destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY}); } function onFailcapturePhoto(message) { console.log("Message = " + message); } function uploadPhoto(imageURI) { var imagefile = imageURI; $('#vImage').attr('src', imagefile); /* Image Upload Start */ var ft = new FileTransfer(); var options = new FileUploadOptions(); options.fileKey="vImage1"; options.fileName=imagefile.substr(imagefile.lastIndexOf('/')+1); options.mimeType="image/jpeg"; var params = new Object(); params.value1 = "test"; params.value2 = "param"; options.params = params; options.chunkedMode = false; ft.upload(imagefile, your_service_url, win, fail, options); } function win(r) { console.log("Code = " + r.responseCode); console.log("Response = " + r.response); //alert($.parseJSON(r.response)) } function fail(error) { console.log("Response = " + error.code); }