6
我正在使用Cordova FileTransfer對象將文件從url下載到設備。使用Cordova FileTransfer將文件下載到設備的下載文件夾
var fileTransfer = new FileTransfer();
var path = cordova.file.dataDirectory;
fileTransfer.download(
fileUrl,
path + "/sample.pdf",
function(theFile) {
console.log("download complete: " + theFile.toURI());
alert("File downloaded to "+cordova.file.dataDirectory);
},
function(error) {
console.log(JSON.stringify(error));
}
);
在這種情況下,文件下載到data/data/com.fileDemo/files/
(我不知道下載是否是成功的,因爲我不能訪問此文件夾。獲得成功的消息download complete: file:///data/data/com.fileDemo/files/sample.pdf
)。 如何使用相同的方法將文件下載到android設備的「Downloads」文件夾中?
我剛剛嘗試過,但gotFs指向應用程序的數據文件夾。而不是根目錄下的下載文件夾。可以訪問根目錄下的下載文件夾嗎? –
對於那些仍然存在這個問題的人來說,無論是'cordova.file.externalRootDirectory +'Download /''還是'fileSystem.root.toURL()+'Download / – REI