将多个图像上传到api - phonegap [英] Upload multiple images to the api - phonegap
本文介绍了将多个图像上传到api - phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Iam在一个phonegap项目,我有一个页面有一些内容发布到服务器。我已将文本内容发布到服务器,如下所示
Iam in a phonegap project, i have a page with some contents to post to the server. I have posted the textual contents to the server as shown below"
$.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的经验。等待你的帮助。感谢。
it all works fine, but i want to upload some images which are taken from device, i dont have have any idea about uploading multiple images since i dont have much experience in uploading files to the api. Waiting for you help. Thanks.
推荐答案
使用phonegap上传图片
Upload image using 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);
}
这篇关于将多个图像上传到api - phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文