找到你要的答案

Q:Cordova/Phonegap File Transfer plugin

Q:科尔多瓦/ PhoneGap文件传输插件

I'm using Cordova/Phonegap and I want to use a plugin for download a file and put it in Downloads folder. I find the plugin FileTransfer http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileTransfer

I'm using this plugin but I don't known the path of folder Download in every device another i want to use the native notification of device...I read that I download the file from remote server but I don't where is and don't show the native console...this is my code in my controller

var fileTransfer = new FileTransfer();
        var uri = encodeURI("http://someUrl/tost.pdf");
        var fileURL = "/sdcard/Download/tost.pdf";

        fileTransfer.download (uri, fileURL, function(entry) {
                console.log("download complete: " + entry.toURL());
            },
            function(error) {
                console.log("download error source " + error.source);
                console.log("download error target " + error.target);
                console.log("upload error code" + error.code);
            },
            false,
            {
                headers: {
                    //"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
                }
            }
        );

Do you know how I can use it with the native notification and the correct path where I must download it?

I'm using Cordova/Phonegap and I want to use a plugin for download a file and put it in Downloads folder. I find the plugin FileTransfer http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileTransfer

我使用这个插件,但我不知道在每个设备的文件夹下载路径另一个我想使用设备的本机通知…我读到我从远程服务器下载文件,但我不在哪里,不显示原生控制台…这是我的代码在我的控制器

var fileTransfer = new FileTransfer();
        var uri = encodeURI("http://someUrl/tost.pdf");
        var fileURL = "/sdcard/Download/tost.pdf";

        fileTransfer.download (uri, fileURL, function(entry) {
                console.log("download complete: " + entry.toURL());
            },
            function(error) {
                console.log("download error source " + error.source);
                console.log("download error target " + error.target);
                console.log("upload error code" + error.code);
            },
            false,
            {
                headers: {
                    //"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
                }
            }
        );

你知道我如何使用它与本机通知和正确的路径,我必须下载吗?

answer1: 回答1:

If you look at the apache/cordova-plugin-file github you can see the locations where you can read from and write to listed in tables for iOS, Android and Blackberry 10.

From the looks of it you are trying to download to a sdcard on Android? The correct url would look like this:

var fileURL = cordova.file.externalRootDirectory+"Download/tost.pdf";

I'm guessing you want to develop you app for iOS and Android, so you should use this url:

var fileURL = cordova.file.dataDirectory+"Download/tost.pdf";

since it's a valid url on both and it's persistent and private.

如果你看看Apache /科尔多瓦插件文件GitHub上你可以看到的地方,你可以读取和写入到表中的列为iOS,Android和黑莓10。

从这你想下载到Android上的SD卡的样子吗?正确的URL看起来像这样:

var fileURL = cordova.file.externalRootDirectory+"Download/tost.pdf";

我猜你想开发你的应用适用于iOS和Android,那么你应该使用这个URL:

var fileURL = cordova.file.dataDirectory+"Download/tost.pdf";

因为它是一个有效的URL两者和它的持久性和私人。

android  ios  cordova  file-upload  cordova-plugins