Reputation: 53
I'm newbie in PhoneGap App Developing. Using Android 4.1.2 with cordova-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. 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/>
Upvotes: 0
Views: 694
Reputation: 53
I solved this my own! It had not enough permission to get FileSystem. Thank You if you tried!
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 1