OOPDeveloper89
OOPDeveloper89

Reputation: 227

Getting error code 5 in Phonegap App

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:

enter image description here

Does anyone know what could be wrong?

Thanks in advance.

Upvotes: 1

Views: 1401

Answers (1)

Jose Ignacio Hita
Jose Ignacio Hita

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

Related Questions