我正在尝试使用Cordova Android应用程序将文件上传到远程服务器,我可以解析文件路径的URL,我可以打印文件的路径,这样它肯定可以找到文件,它确实存在。但每当我上传文件时,它都会失败,错误代码为1,这意味着找不到该文件。该文件位于我的SD卡上,我使用该应用程序创建它。这是我上传文件的代码。
function upload() {
window.resolveLocalFileSystemURL(
"file:///storage/emulated/0/testFile5.txt", gotFileAddress,
error);
}
function error() {
alert("no file");
}
function gotFileAddress(fileEntry) {
fileURL = fileEntry.toURL();
server = encodeURI("http://test.server.com/upload");
alert(fileURL)
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "text/plain";
alert("a");
var params = {};
params.value1 = "test";
params.value2 = "param";
alert("b");
options.params = params;
alert("c");
var ft = new FileTransfer();
ft.upload(fileURL, server, win, fail, options);
alert("d");
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source +
" \n upload error target " + error.target);
}
} // end of upload
有人有什么建议吗?我多年来一直坚持这个