我正在使用Cordova(5.4)爲Android和Iphone創建應用程序。一切都很好,除非我想用科爾多瓦的插件「FileTransfer」下載圖片,並且我在路徑上遇到了一些問題。FileTransfer Cordova下載路徑
如果我使用文件傳輸這樣的:
uri = encodeURI('http://example.com/myImage.png'),
fileURL = '/sdcard/Download/' + 'myImage.png',
fileTransfer.download(
uri,
fileURL,
function (entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log(error);
},
false,
{
headers: {
"authorization": 'Bearer ' + token
}
}
);
這工作得很好。但是我想要一個適用於Android和Iphone(不是靜態的)的路徑,並且如果可能的話,用戶可以直接在他們的畫廊中看到這些圖像。
檢查我試過插件描述:
fileURL = 'cdvfile://localhost/persistent/myImg.png'
但這種失敗與FileTrasferError:
"/data/data/com.aco.plus/files/files/myImg.png: open failed: ENOTDIR (Not a directory)"
檢查答案圍繞我想也是:
uri = encodeURI('http://example.com/myImage.png');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileTransfer.download(
uri,
fileSystem.root.toURL() + '/' + 'myImg.png',
function (entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log(error);
},
false,
{
headers: {
"authorization": 'Bearer ' + token
}
}
);
});
而且我得到了同樣的錯誤。
我很迷茫。任何人都知道我能做什麼?我相當肯定,這是一個比靜態路由更好的方式。
我知道它很老的問題,但你能解決這個問題問題。因爲我在將文件保存到下載文件夾時也遇到了麻煩。 – Ironic
如果下載成功,您應該重新掃描設備存儲,因爲Cordova不知道文件是否已下載。所以我做了一個插件,它是一個插件,下載後更新畫廊。 [cordova-plugin-gallery-refresh](https://www.npmjs.com/package/cordova-plugin-gallery-refresh) –