我在使用 cordova 插件文件传输时遇到了一些问题。这是我的代码:
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry) {
var sPath = fileEntry.fullPath.replace("dummy.html", "");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download( 'http://cordova.apache.org/images/cordova_bot.png', sPath + photo.original_name,
function (theFile) {
alert('success: ' + JSON.stringify(theFile));
console.log("download complete: " + theFile.toURI());
// showLink(theFile.toURI());
},
function (error) {
alert('error: ' + JSON.stringify(error));
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
},
true
);
})
},
function (error) {
alert('error request: ' + JSON.stringify(error));
}
);
返回 fileTransfer.download 的错误回调,错误代码为 3,http 401。 我已经更新了 File 和 FileTransfer 插件,我的 cordova 版本是 4.3.0。 还检查了我的 config.xml 的
<access origin="*" />
但它就在那里。 我尝试添加标题 Connection: close,但没有结果。 也尝试将下载的第四个参数设置为其默认值(false) - 没有运气。
在 Android 平板电脑上进行测试。
有人有什么事吗?谢谢!
最佳答案
刚刚找到了我的问题的“解决方案”。 我所做的是将文件传输插件版本从 0.5.0 降级到 0.4.8。
如果有人遇到类似的问题,请执行以下操作:
- 通过运行“cordova plugins list”和“cordova plugin remove name_from_list”来删除现有文件传输插件
- 转到https://github.com/apache/cordova-plugin-file-transfer/releases并下载0.4.8版本的zip文件。
- 将文件解压到 cordova 应用程序的根目录中
- 运行“cordova 插件添加unzipped_folder 路径”
就是这样。看起来效果不错,至少返回了成功回调,没有真正测试更多。
关于javascript - Cordova FileTransfer 下载 - 总是返回错误 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632141/