【发布时间】:2018-02-18 10:13:04
【问题描述】:
请帮我解决这个问题,我从上周开始尝试解决这个问题。使用科尔多瓦文件传输插件我尝试将我的图像上传到生产服务器 但是我收到错误代码 1。
我检查了源路径和目标路径都可以访问。请找到我的 cordova 设置版本。
Cordova -> 7.1.0,Phonegap -> 7.1.1,cordova-plugin-file-transfer-> spec=1.7 .1
代码:
function staticpathu_upload() {
var fileURL = 'https://example.com/Al_2_1518090802.jpg';
var uri = encodeURI('https://example.com/dummy.php');
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";
var ft = new FileTransfer();
ft.upload(fileURL, uri, onSuccess, onError, options);
function onSuccess(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function onError(error) {
console.log(error);
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
}
错误:
FileTransferError {
code: 1,
source: "https://example.com/Al_2_1518090802.jpg",
target: "https://example.com/dummy.php",
http_status: null,
body: null,
}
【问题讨论】:
-
签入到 window.resolveLocalFileSystemURL() 和 toInternalURL 以获取源代码。我的应用程序这样调用(它在生产和工作中): window.resolveLocalFileSystemURL(imageUri, function (entry) { getB64Image(entry.toInternalURL()); }); //其中getB64Image是创建FileUploadOptions/FileTransfer/etc,并上传的函数。
标签: javascript android cordova image-uploading