我正在使用iOS Cordova应用程序,我想使用文件传输插件更改个人资料图片,我只想从手机库中选择一张照片并上传到服务器:我试过这个,它不起作用,我感谢任何帮助,如果需要,我会提供其他细节:)
function loadPicture()
{
navigator.camera.getPicture(onSuccess, function(message) { alert ("Ouups!"); }, { destinationType: Camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, quality: 80
});
function onSuccess(imageURI) {
//alert(imageURI.toString());
var myDate = new Date();
var date = myDate.getFullYear() +"-" + (myDate.getMonth() + 1) +"-" + myDate.getUTCDate() +"_" + myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds();
var options = new FileUploadOptions();
var userid = localStorage.getItem("userid");
options.fileKey = "file";
options.fileName = "photo-" + userid + "-" + date + ".jpeg";
options.mimeType = "image/jpeg";
var params = {};
params.userid = localStorage.getItem("userid");
params.date = date;
params.account = "user";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://62.210.192.92/AE/web/upload.php"), win, fail, options);
alert("Done", "", "Profile picture");
reload();
var win = function (r) {}
var fail = function (error) {}
}
function onFail(error) {}
}