流星科尔多瓦 FileTransfer.download 错误 CONNECTION_ERR
Meteor Cordova FileTransfer.download error CONNECTION_ERR
我正在尝试从外部服务器下载文件并将其保存在本地到 andriod 的设备存储中。我正在使用:
var downloadFile = function () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var dir = fs.root.getDirectory("appImages", {create: true, exclusive: false}, function (dirEntry) {
var file = dirEntry.getFile("image.png", {create: true, exclusive: false}, function (fileEntry) {
var filePath = fileEntry.toURL();
var fileTransfer = new FileTransfer();
console.log('starting file download: ' + "https://www.google.com/images/srpr/logo11w.png" + ' to ' + filePath);
fileTransfer.download(
"https://www.google.com/images/srpr/logo11w.png",
filePath,
function () {
console.log('save');
},
function (error) {
console.log('failed to save image: ' + filePath + ' (error: ' + error.http_status + ')');
console.log(JSON.stringify(error));
},
true
);
});
}, function (error) {
console.log(JSON.stringify(error));
});
}, function (error) {
console.log(JSON.stringify(error));
});
};
我收到错误:
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:55) starting file download: https://www.google.com/images/srpr/logo11w.png to file:///storage/emulated/0/appImages/image.png
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:69) failed to save image: file:///storage/emulated/0/appImages/image.png (error: 401)
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:70) {"code":3,"source":"https://www.google.com/images/srpr/logo11w.png","target":"file:///storage/emulated/0/appImages/image.png","http_status":401,"body":null,"exception":null}
文件路径已创建,我可以浏览到 /appImages
并看到有损坏的 image.png
。在我的 AndroidManifest.xml
我还有:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /
我的设备也连接到互联网。感谢您的帮助!
这个问题的原因很少。
1- 没有互联网连接或连接到 wifi。
2- AndroidManifest.xml
中没有互联网许可
<uses-permission android:name="android.permission.INTERNET" />
这个问题把我逼疯了,但我终于弄明白了。我使用的文件传输版本不能很好地与 meteor 配合使用。没有工作的版本是 0.5.0
而不是我使用版本 0.4.3
现在一切都很好,
已删除:meteor remove cordova:org.apache.cordova.file-transfer@0.5.0
已添加:meteor add cordova:org.apache.cordova.file-transfer@0.4.3
现在一切正常。
我正在尝试从外部服务器下载文件并将其保存在本地到 andriod 的设备存储中。我正在使用:
var downloadFile = function () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var dir = fs.root.getDirectory("appImages", {create: true, exclusive: false}, function (dirEntry) {
var file = dirEntry.getFile("image.png", {create: true, exclusive: false}, function (fileEntry) {
var filePath = fileEntry.toURL();
var fileTransfer = new FileTransfer();
console.log('starting file download: ' + "https://www.google.com/images/srpr/logo11w.png" + ' to ' + filePath);
fileTransfer.download(
"https://www.google.com/images/srpr/logo11w.png",
filePath,
function () {
console.log('save');
},
function (error) {
console.log('failed to save image: ' + filePath + ' (error: ' + error.http_status + ')');
console.log(JSON.stringify(error));
},
true
);
});
}, function (error) {
console.log(JSON.stringify(error));
});
}, function (error) {
console.log(JSON.stringify(error));
});
};
我收到错误:
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:55) starting file download: https://www.google.com/images/srpr/logo11w.png to file:///storage/emulated/0/appImages/image.png
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:69) failed to save image: file:///storage/emulated/0/appImages/image.png (error: 401)
I20150303-14:44:20.104(-7) (android:http://meteor.local/test.js:70) {"code":3,"source":"https://www.google.com/images/srpr/logo11w.png","target":"file:///storage/emulated/0/appImages/image.png","http_status":401,"body":null,"exception":null}
文件路径已创建,我可以浏览到 /appImages
并看到有损坏的 image.png
。在我的 AndroidManifest.xml
我还有:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /
我的设备也连接到互联网。感谢您的帮助!
这个问题的原因很少。
1- 没有互联网连接或连接到 wifi。
2- AndroidManifest.xml
中没有互联网许可<uses-permission android:name="android.permission.INTERNET" />
这个问题把我逼疯了,但我终于弄明白了。我使用的文件传输版本不能很好地与 meteor 配合使用。没有工作的版本是 0.5.0
而不是我使用版本 0.4.3
现在一切都很好,
已删除:meteor remove cordova:org.apache.cordova.file-transfer@0.5.0
已添加:meteor add cordova:org.apache.cordova.file-transfer@0.4.3
现在一切正常。