简体   繁体   English

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

[英]How to fix Error Code 1 on PhoneGap FileTransfer()

I'm newbie in PhoneGap App Developing. 我是PhoneGap应用开发的新手。 Using Android 4.1.2 with cordova-2.6.0 . Android 4.1.2cordova-2.6.0结合使用 What is wrong here? 怎么了 Can anyone help me doing this.... 谁能帮我做到这一点。

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

It returns error code 1 which means FILE NOT FOUND. 它返回错误代码1,表示未找到文件。 But I tried every way I could. 但是我尽了一切努力。

<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/>

I solved this my own! 我自己解决了! It had not enough permission to get FileSystem. 它没有足够的权限来获取FileSystem。 Thank You if you tried! 谢谢,如果您尝试过!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM