【发布时间】:2016-12-13 19:50:14
【问题描述】:
在我开始之前,我尝试了以下堆栈溢出的答案。
Download file to downloads folder ios/android using phonegap
FileTransfer Cordova download path
Download a file to Downloads folder of device using Cordova FileTransfer
http://www.phonegaptutorial.com/downloading-an-image-from-the-internet-with-phonegap/
但一点运气都没有。
我正在尝试从 Internet 下载文件。 我的目标是在安卓手机的下载文件夹中下载文件。
我尝试了上述所有答案,并且我使用了cordova网站上的cordova示例。
https://cordova.apache.org/docs/en/2.0.0/cordova/file/filetransfer/filetransfer.html
function downloadCL(){
var url = "http://www.phonegaptutorial.com/wp-content/uploads/examples/phonegap-logo.png";
// we need to access LocalFileSystem
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, function(fs)
{
// create the download directory is doesn't exist
fs.root.getDirectory('downloads', { create: true });
// we will save file in .. downloads/phonegap-logo.png
var filePath = fs.root.fullPath + '/downloads/' + url.split('/').pop();
var fileTransfer = new window.FileTransfer();
var uri = encodeURI(decodeURIComponent(url));
fileTransfer.download(uri, filePath, function(entry)
{
alert("Successfully downloaded file, full path is " + entry.fullPath);
},
function(error)
{
console.log("Some error " + error.code + " for " + url +);
},
false);
}
};
};
任何建议如何实现这一点。
【问题讨论】:
-
为什么要投反对票?它有什么问题?至少说明原因。
标签: android cordova phonegap-plugins