issue when uploading multiple images - phonegap

雨燕双飞 提交于 2019-12-13 21:59:03

问题


Iam doing a phonegap project, here iam uploading multiple images to the server as shown below, and i got success status for both image upload, but when iam checking at backend it shows only one image as uploaded (the second one). Please check whether any mistakes in upload code, and help me.

  var options = new FileUploadOptions();
                options.fileKey="uploadfile";
                options.fileName=randomNumber.toString().concat(fileNameSelected);
                options.mimeType="image/jpeg";
                options.chunkedMode = false;

                                var ft = new FileTransfer();
                              // first upload
                                ft.upload(i1,'http://xx.xx.xx/mobapp/api/upload-image', 
                                function (r){ 
                                   console.log("ft.upload one"+JSON.stringify(r));
                                   //  second upload
                                   ft.upload(i2,'http:/xxx.xx.xx/mobapp/api/upload-image',
                                   function(r){console.log("ft.upload two"+JSON.stringify(r));},
                                   function(error){alert("image upload two failed");},options);
                                },function(error)
                                {alert("image upload failed");},options);

Thanks.


回答1:


1) Check this post to add multiple image on your image tag

Upload multiple images to the api - phonegap

2) On submit button get image src

On your submit buton add

if($('#vImage1').attr('src')){
   /* Image Upload1 Start */
     imagefile = $('#vImage1').attr('src');
     uploadPhoto(imagefile, "vImage1");
  /* Image Upload End */
}
if($('#vImage2').attr('src')){
    /* Image Upload2 Start */
     imagefile = $('#vImage2').attr('src');
     uploadPhoto(imageURI, "vImage2");         
    /* Image Upload End */
 }

 function uploadPhoto(imageURI, vImage) {
  var imagefile = imageURI; 
   /* Image Upload Start */
  var ft = new FileTransfer();                     
  var options = new FileUploadOptions();                      
  options.fileKey= vImage;                      
  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);   
 }

Processing multiple simultaneous uploads with Cordova

Simultaneous uploads with Cordova

More....



来源:https://stackoverflow.com/questions/20463506/issue-when-uploading-multiple-images-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!