cordova:从url下载到android下载文件夹 [英] cordova: download from url to android download folder

查看:113
本文介绍了cordova:从url下载到android下载文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始之前,我尝试过以下堆栈溢出的答案.

Well before i start i tried below answers from stack overflow.

使用phonegap下载文件以下载ios/android文件夹

FileTransfer Cordova下载路径

将文件下载到使用Cordova FileTransfer的设备

http://www.phonegaptutorial. com/从带有电话间隙的互联网上下载图像/

但是根本没有运气.

我正在尝试从Internet下载文件. 我的目标是在Android手机的下载文件夹中下载文件.

I am trying to download a file from internet. My target is to download the file in download folder on Android phone.

我尝试了以上所有答案,并且我使用了科尔多瓦站点上的科尔多瓦示例.

I tried all the above answers and also i have used cordova example from cordova site.

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);
}
                          };
};

任何人都建议如何实现这一目标.

Any advise how to achieve this.

推荐答案

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

Fork,
you have to choose download file url,
local download file located here -
file:///storage/emulated/0/download This link may help you -

Cordova-将文件下载到下载文件夹中

添加了要下载的文件传输插件,例如-

Added file transfer plugin to download such as -

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

根据要求选择任何内容

这篇关于cordova:从url下载到android下载文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆