Reputation: 227
I am working on a phonegap app. In my app the user can download files like pdf, jpg,...
I found some tutorials, but currently I am not able to create a file. Here is my javascript code:
var remoteFile = 'http://src/to/an/image.jpg';
var localName = 'abcd.jpg';
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(
localName ,
{create : true, exclusive : false},
function(file) {
alert('SUCCESS');
},
function(error) {
// I get error code 5...
alert(error.code);
});
},
function(err) {});
The plugins "file" and "file-transfer" are installed. In AndroidManifest.xml I add:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I also add the url for the jpg file to the whitelist. In config.xml:
<access origin="*"/>
Logcat says:
Does anyone know what could be wrong?
Thanks in advance.
Upvotes: 1
Views: 1401
Reputation: 994
Just in case you are here with the same problem as me, my problem was I was giving the file a name containing invalid characters. I was building a system to log application events and I created the file like this:
dir.getFile("log123-" + new Date().toString() + ".txt", ...
I have used a better name and it works!
Upvotes: 1