如何修复PhoneGap FileTransfer()上的错误代码1

时间:2014-09-25 09:31:33

标签: android cordova

我是PhoneGap App Develop的新手。 将 Android 4.1.2 cordova-2.6.0 配合使用。 这有什么不对? 任何人都可以帮我这样做....

    function photoDownload(url, target) {
    var url = encodeURI(url);
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
        var imagePath = fs.root.fullPath + "/" + target; // full file path
        // fs.root.fullPath returns "file:///storage/sdcard0/"
        //var imagePath = "/storage/sdcard0/" + target; // try another full file path
        var fileTransfer = new FileTransfer();
        fileTransfer.download(
            url,
            imagePath,
            function (entry) {
                alert("success" + entry.fullPath); // entry is fileEntry object
            },
            function (error) {
                alert("error source " + error.source);
                alert("error target " + error.target);
                alert("error code "   + error.code);
            },
            true,
            {
                headers: {}
            }
        );
    })
}

它返回错误代码1,这意味着FILE NOT FOUND。 但我尽我所能地尝试过。

<div style="font-size: 22px;" onclick="photoDownload('url', 'save');">Download</div><br/><br/>

<div style="font-size: 22px;" onclick="photoDownload('http://aponblog.com/inc/images/globe.png', 'globe.png');">Download</div><br/>
<div style="font-size: 22px;" onclick="photoDownload('http://aponblog.com/inc/images/globe.png', 'TestFolder/globe.png');">TestFolder/Download</div><br/><br/>

<div style="font-size: 22px;" onclick="photoDownload('https://graph.facebook.com/simplyapon/picture?width=100&height=100', 'simplyapon.jpg');">S Download</div><br/>
<div style="font-size: 22px;" onclick="photoDownload('https://graph.facebook.com/simplyapon/picture?width=100&height=100', 'TestFolder/simplyapon.jpg');">S TestFolder/Download</div><br/>

1 个答案:

答案 0 :(得分:1)

我自己解决了这个问题!它没有足够的权限来获取FileSystem。 谢谢你,如果你尝试过!

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />