如何将文件移动到下载文件夹? [英] How to move file to download folder?

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

问题描述

在我的应用程序中,我获取文件(doc,pdf,jpeg,...)的base64数据,并用FileWriter编写. 该文件现在位于我的应用程序目录中.但是我需要将其移至Android设备的下载目录. 不能通过以下代码进行访问:

In my app I get base64 data of a file (doc, pdf, jpeg,...) and write it with FileWriter. The file is now in my app-directory. But I need to move it to the Download directory of Android device. Is it not possible to get access with this code:

 window.resolveLocalFileSystemURL('content:///storage/emulated/0/Download', function(a) {},fail}; 

我总是收到错误代码1.

I always get error code 1.

在我的Android manifest.xml中,我目前仅具有WRITE_EXTERNAL_STORAGE权限.这样够了吗?

In my android manifest.xml I currently just have WRITE_EXTERNAL_STORAGE permission. Is this enough?

谢谢.顺便说一下,我使用 cordova3.4 android 4.3 .

Thanks. By the way I use cordova3.4 and android 4.3.

推荐答案

sdcard路径在设备之间更改.

The sdcard path changes from device to device.

我建议您阅读文件系统插件doc 获取完整信息.

I suggest you read the File System plugin doc for complete information.

如果您还没有修改config.xml来添加<preference name="AndroidPersistentFileLocation" value="Internal" />,我会说这应该可以完成工作:

If you haven't modified config.xml to add <preference name="AndroidPersistentFileLocation" value="Internal" />, I'd say that this should do the job :

window.resolveLocalFileSystemURI('/Download', function(dirEntry) {},fail};

或其他方式:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function (fs) {
        fs.root.getDirectory("/Download", {
            create : false,
            exclusive : false
        }, function (dirEntry) { //success
            //do here what you need to do with Download folder
        }, function () {
            //error getDirectory
        });
    },
    function () {
    //error requestFileSystem
    }
);

这篇关于如何将文件移动到下载文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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