【问题标题】:cordova: download from url to android download folder科尔多瓦:从 url 下载到 android 下载文件夹
【发布时间】: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


【解决方案1】:

叉子,
您必须选择下载文件的网址,
本地下载文件位于此处 -
文件:///存储/模拟/0/下载 此链接可能对您有所帮助 -

Cordova - Download a file in download folder

添加文件传输插件下载,如-

https://github.com/cfjedimaster/Cordova-Examples/tree/master/asyncdownload

根据需要任意选择

【讨论】:

    猜你喜欢
    • 2012-09-21
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    相关资源
    最近更新 更多