简体   繁体   中英

issue when uploading multiple images - phonegap

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) 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....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM