我正面临着在ios phonegap中上传文件的一个大问题,但同样适用于android。当我从iphone上传文件时,它给出了200响应即成功和发送的字节。但是服务器响应是目标丢失,这意味着文件没有在服务器上接收,请尽可能为我提供任何解决方案。因为无法实现项目的死线。 谢谢。我要在这里分享我的代码。
function upload_demo() {
// Retrieve image file location from specified source
navigator.camera.getPicture(
uploadPhoto1,
function(message) { alert('get picture failed'); },
{
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI,
sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto1(imageURI) {
alert(imageURI);
alert(activefolder);
var url="https://server.com/****";
alert(url);
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var headers = {
"Authorization" : auth
};
options.headers = headers;
var params = {};
params.target = activefolder;
options.params = params;
options.httpMethod="POST";
alert(JSON.stringify(options));
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(url), win1, fail1, options,true);
}
function win1(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail1(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
答案 0 :(得分:0)
如果有帮助,请查看以下链接: -
http://www.zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap
options.chunkedMode = false;
而不是检查包含所有权限的plist