Cordova-Examples icon indicating copy to clipboard operation
Cordova-Examples copied to clipboard

Read Text File: File Error Code 1

Open mariomka opened this issue 11 years ago • 13 comments
trafficstars

Hi,

I just copy your code into a new cordova project after add android plataform and file plugin, then I get:

FileError code 1

"1" is File not found

mariomka avatar Aug 02 '14 10:08 mariomka

You mentioned you copied it into a new project, did you modify the JS code at all?

cfjedimaster avatar Aug 02 '14 14:08 cfjedimaster

Yes, I used all of your code.

mariomka avatar Aug 03 '14 15:08 mariomka

Hmm. Can you share a Dropbox link to the project? I'll take a look, but if the www folder is the exact same as mine, then I'm not sure what to suggest. Did you test on a device or in the Android emulator?

cfjedimaster avatar Aug 03 '14 15:08 cfjedimaster

I tried in both: emulator (Android 4.4.2) and device (Nexus 5 Android 4.4.4).

Cordova version 3.5.0-0.2.6

https://dl.dropboxusercontent.com/u/18204615/testReadlFile.tar.gz

Is a strange behavior...

mariomka avatar Aug 05 '14 13:08 mariomka

I can confirm - fails on Android. :(

cfjedimaster avatar Aug 07 '14 19:08 cfjedimaster

Ok, I'm at a loss. I'm going to dig around a bit.

cfjedimaster avatar Aug 07 '14 19:08 cfjedimaster

Ok, this looks to be an Android bug. :(

https://issues.apache.org/jira/browse/CB-7273

I'm sorry I never tested this (although I thought I did) - I must have assumed it was so simple that I couldn't imagine it not working.

cfjedimaster avatar Aug 07 '14 20:08 cfjedimaster

This bug got just a minor priority. Is there any other reliable method to read text (JSON) files from the application directory? (This is a requirement for an offline app.)

ghost avatar Aug 16 '14 00:08 ghost

XHR?

cfjedimaster avatar Aug 16 '14 02:08 cfjedimaster

XHR for local file system? That's new to me.

What I'm looking for is loading JSON files which are installed with the app on the device, in a directory such as www/json/ .

ghost avatar Aug 16 '14 04:08 ghost

BTW, a reliable way to do that was using RequireJS, however, since cordova version 3.5.0 there seem to be again conflicts when using booth API's together.

ghost avatar Aug 16 '14 04:08 ghost

By XHR I just mean Ajax. If you look at the source code in the demo, I think I even mention that.

On Fri, Aug 15, 2014 at 11:15 PM, bardu [email protected] wrote:

BTW, a reliable way to do that was using RequireJS, however, since cordova version 3.5.0 there seem to be again conflicts when using booth API's together.

— Reply to this email directly or view it on GitHub https://github.com/cfjedimaster/Cordova-Examples/issues/2#issuecomment-52383016 .

Raymond Camden, Web Developer for Adobe

Email : [email protected] Blog : www.raymondcamden.com Twitter: raymondcamden

cfjedimaster avatar Aug 16 '14 10:08 cfjedimaster

If anyone is still searching, this is a working solution for files in www/ (or www/videos/ respectively).

var myFilename = "testvid.webm";
var myUrl = cordova.file.applicationDirectory + "www/videos/" + myFilename;
var fileTransfer = new FileTransfer();
var filePath = cordova.file.dataDirectory + myFilename;
var allowFromAll = false;

fileTransfer.download(encodeURI(myUrl), filePath, (function(entry) {
  /*
  res = "download complete:\n"
  res += "fullPath: " + entry.fullPath + "\n"
  res += "localURL: " + entry.localURL + "\n"
  alert(res += "nativeURL: " + entry.nativeURL + "\n")
   */
  var vid = document.getElementById("someID");
  vid.src = entry.nativeURL;
  angular.element(v).loop = true;
}), (function(error) {
  alert("Video download error: source " + error.source);
  alert("Video download error: target " + error.target);
}), allowFromAll, {
  headers: {
    Authorization: "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
  }
});

(try to set allowFromAll to true if it does not work for you.)

mamrehn avatar Oct 07 '14 12:10 mamrehn