上传多个图像时出现问题 - phonegap [英] issue when uploading multiple images - phonegap
问题描述
Iam做一个phonegap项目,这里iam上传多个图像到服务器,如下所示,我得到成功
状态的图像上传,但是当iam检查在后端它只显示一个上传的图像(第二个)。请检查上传代码是否有任何错误,并帮助我。
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));
//第二次上传
ft.upload(i2,'http:/xxx.xx.xx/mobapp/ api / upload-image',
function(r){console.log(ft.upload two+ JSON.stringify(r));},
function(error){alert上传两个失败的);},选项);
},函数(错误)
{alert(image upload failed);},options);
谢谢。
1)检查此信息以在图片标签上添加多个图片
2)在提交按钮获取图像src
在您的提交添加
if($('#vImage1')。attr('src')){
/ * Image Upload1开始* /
imagefile = $('#vImage1')。attr ');
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;
/ *图片上传开始* /
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处理多个同时上传 >
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
这篇关于上传多个图像时出现问题 - phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!