1

Hi I'm trying to use the cordova file plugin in my application but I'm hitting a little problem.

the file plugin apparently has it's own constructor for FileReader, which doesn't include the add/removeEventListener part.

The problem is I have another package that needs this.

Here is the code for that

  var reader = new FileReader()

  function onLoadEnd (e) {
    reader.removeEventListener('loadend', onLoadEnd, false)
    if (e.error) cb(e.error)
    else cb(null, toBuffer(reader.result))
  }

  reader.addEventListener('loadend', onLoadEnd, false)
  reader.readAsArrayBuffer(blob)

I have tried renaming cordova file's constructor to something else but it still seems to override the original FileReader

In their constructor they save the "original FileReader" as _realReader

The only way I've been able to solve this is by wrapping the code in an

document.addEventListener('deviceready', function () { /* above function */ });

So that the code doesn't run until it's overriden by the plugin, and then use the _realReader but that doesn't always work as I navigate through the app and gives me a white screen sometimes before a route has been loaded.

Anyone that has any good suggestions for this?

1

1 Answer 1

1

I ended up changing the target to not override the original FileReader by doing

<clobbers target="window.FileReaders" />

instead of <clobbers target="window.FileReader" />

Probably not the best solution but now it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.