上传多张图片时出现问题 - phonegap

时间:2013-12-09 05:03:22

标签: jquery file-upload cordova file-transfer

我正在做一个phonegap项目,这里我将多个图像上传到服务器,如下图所示,我获得了success状态以进行图片上传,但是当我在后端检查时,它只显示一个上传的图像(第二个)。请检查上传代码是否有任何错误,并帮助我。

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

感谢。

1 个答案:

答案 0 :(得分:0)

1)检查此帖子,在图片标签上添加多个图片

Upload multiple images to the api - phonegap

2)在提交按钮上获取图像src

在你的提交按钮上添加

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);   
 }

使用Cordova处理多个同步上传

Simultaneous uploads with Cordova

More....