Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File write, create, readAsText broken #464

Closed
pgg opened this issue Aug 19, 2016 · 8 comments
Closed

File write, create, readAsText broken #464

pgg opened this issue Aug 19, 2016 · 8 comments

Comments

@pgg
Copy link

pgg commented Aug 19, 2016

File writeFile, createFile replace as boolean value = true does not work. readAsText fails expecting a blob . . . I am trying to write a simple text file (that should be replaced every time) and read its contents back . . . ionic-native@1.3.16

This is the only way I could get it to work:

Write:

File.removeFile(window['cordova'].file.dataDirectory, 'file.json')
    .then(() => File.createFile(window['cordova'].file.dataDirectory, 'file.json', false)
        .then(fileEntry => File.writeExistingFile(window['cordova'].file.dataDirectory, 'file.json', JSON.stringify({ key: 'value' })));

Read:
this.http.get(window['cordova'].file.dataDirectory + 'security.json').map(res => res.json().key);

@rapropos
Copy link
Contributor

Hopefully this PR will address writeFile, but createFile doesn't seem to have a similar problem, so I'm not sure what's going on there.

@ihadeed
Copy link
Collaborator

ihadeed commented Aug 23, 2016

@pgg the PR was merged and is now released, please update to v1.3.17 and let us know if you still have any issues.

@pgg
Copy link
Author

pgg commented Aug 23, 2016

Now writeFile with boolean true only works if there is already a file. Also getting strange behaviour with other File operations all round, will test and log them asap, but I suggest an all round File operations sanity check/test . . .

@pgg
Copy link
Author

pgg commented Aug 23, 2016

@ihadeed What is the correct way to read a text file? File.readAsText does not work . . .

@ramonsan
Copy link

ramonsan commented Aug 24, 2016

All readAsXXXX still having 'not Blob' error, i.e.:

TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.

EDIT: #479 fixes this issue.

@mnasyrov
Copy link

mnasyrov commented Sep 2, 2016

Took a quick look in sources of File.writeFile() method under src/plugins/file.ts.

It seems like things are messed here:

  • specified WriteOptions via replaceOrOptionsparameter is never used because internal opts object is constructed only for a case when replaceOrOptions is true.
  • opts has WriteOptions type, but it is passed to File.getFile() which expects Flags type.

Hope it'll help to fix the issue.

@ihadeed
Copy link
Collaborator

ihadeed commented Oct 12, 2016

@pgg Can you try with the latest version v2.2.2 and report back if you still have any issue? Thanks.

@ihadeed ihadeed closed this as completed Oct 12, 2016
@iron9light
Copy link

iron9light commented Mar 20, 2017

File.readAsText still don't work. It seems the promise will not complete forever.
v2.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants