I use Cordova (5.4) to create applications for Android and Iphone. Everything is going well, except that I want to upload images using the Cordova plugin " FileTransfer ", and I have some problems with this path.
If I use FileTransfer as follows:
uri = encodeURI('http://example.com/myImage.png'),
fileURL = '/sdcard/Download/' + 'myImage.png',
fileTransfer.download(
uri,
fileURL,
function (entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log(error);
},
false,
{
headers: {
"authorization": 'Bearer ' + token
}
}
);
It works great. But I needed a way that worked on Android and Iphone (and not on static), and if it could be so that the user could see this image directly in his gallery.
Checking the plugin description I tried:
fileURL = 'cdvfile://localhost/persistent/myImg.png'
But this does not work with FileTrasferError:
"/data/data/com.aco.plus/files/files/myImg.png: open failed: ENOTDIR (not a directory)"
Checking the answers, I also tried:
uri = encodeURI('http://example.com/myImage.png');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileTransfer.download(
uri,
fileSystem.root.toURL() + '/' + 'myImg.png',
function (entry) {
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log(error);
},
false,
{
headers: {
"authorization": 'Bearer ' + token
}
}
);
});
And I got the same error.
. - , ? , , .