cdvfile throws 404 not found error in Phonegap 5.1.1

  • 2
  • Problem
  • Updated 4 years ago


Copying a file to cdvfile://localhost/temporary/ -or- cdvfile://localhost/persistent/ and trying to display it throws a 404 error. Works fine in 3.7.0.

config.xml whitelist settings:

allow-intent href="*"
allow-navigation href="*"
access origin="*"
access origin="cdvfile://*"


index.html:

meta http-equiv="Content-Security-Policy" content="default-src * data: cdvfile:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"


The code:

var fileTransfer = new FileTransfer();

fileTransfer.download(
encodeURI("https://upload.wikimedia.org/wikipedia/meta/6/6d/Wikipedia_wordmark_1x.png"),
'cdvfile://localhost/temporary/logo.jpg',
function(entry) {
console.log("download complete: " + entry.toURL());
$('#container-load-html').html('');
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);


EDIT: Works fine in 3.7.0 and 5.1.1 on iOS, maybe file plugin related?
Photo of WeaponX86

WeaponX86

  • 37 Posts
  • 1 Reply Like

Posted 5 years ago

  • 2
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Photo of Yi Ming Kuan

Yi Ming Kuan

  • 1840 Posts
  • 78 Reply Likes
Does the same issue occur if you use the latest File/File Transfer plugin from the NPM source?

-yiming
Photo of WeaponX86

WeaponX86

  • 37 Posts
  • 1 Reply Like
Yes the app id is 1484684. Here is the config.xml,
http://www.pastebin.ca/3148586
Photo of WeaponX86

WeaponX86

  • 37 Posts
  • 1 Reply Like
Bump. Is anyone able to use cdvfile with version 3.0.0 of the file plugin?
https://www.npmjs.com/package/cordova...
Photo of Victor Dias

Victor Dias

  • 32 Posts
  • 2 Reply Likes
I'm facing exactly the same issue, tested on Android 5.1.1, 5.1.0 and 4.1.1.

I use File Plugin 4.1.0.
Set access origin="cdvfile://*" on my config.xml
Add cdvfile on my CSP

Did you find a solution or workaround ?
Photo of WeaponX86

WeaponX86

  • 37 Posts
  • 1 Reply Like
I have it working.

In my config.xml:

<!-- Origin -->
<access origin="*"/>
<!-- allow local pages -->
<access origin="cdvfile://*" launch-external="yes" />

<!-- Navigation -->
<allow-navigation href="*" />
<allow-navigation href="cdvfile://*"/>

<!-- Intent -->
<allow-intent href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>


In my index.html:

<meta http-equiv="Content-Security-Policy" content="default-src * data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
Photo of Victor Dias

Victor Dias

  • 32 Posts
  • 2 Reply Likes
Thanks WeaponX86, after adding <allow-navigation href="cdvfile://*"/> it solves my issue.

No need for me to add launch-external option.