Skip to content

Read Text File: File Error Code 1 #2

@mariomka

Description

@mariomka

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

Activity

cfjedimaster

cfjedimaster commented on Aug 2, 2014

@cfjedimaster
Owner

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

mariomka

mariomka commented on Aug 3, 2014

@mariomka
Author

Yes, I used all of your code.

cfjedimaster

cfjedimaster commented on Aug 3, 2014

@cfjedimaster
Owner

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?

mariomka

mariomka commented on Aug 5, 2014

@mariomka
Author

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...

cfjedimaster

cfjedimaster commented on Aug 7, 2014

@cfjedimaster
Owner

I can confirm - fails on Android. :(

cfjedimaster

cfjedimaster commented on Aug 7, 2014

@cfjedimaster
Owner

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

cfjedimaster

cfjedimaster commented on Aug 7, 2014

@cfjedimaster
Owner

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.

ghost

ghost commented on Aug 16, 2014

@ghost

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.)

cfjedimaster

cfjedimaster commented on Aug 16, 2014

@cfjedimaster
Owner

XHR?

ghost

ghost commented on Aug 16, 2014

@ghost

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

ghost commented on Aug 16, 2014

@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.

cfjedimaster

cfjedimaster commented on Aug 16, 2014

@cfjedimaster
Owner

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 notifications@github.com 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
#2 (comment)
.

Raymond Camden, Web Developer for Adobe

Email : raymondcamden@gmail.com
Blog : www.raymondcamden.com
Twitter: raymondcamden

mamrehn

mamrehn commented on Oct 7, 2014

@mamrehn

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cfjedimaster@mariomka@mamrehn

        Issue actions

          Read Text File: File Error Code 1 · Issue #2 · cfjedimaster/Cordova-Examples