Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

[Android] File Creation Error: parent path may not exist #167

Closed
ksegla opened this issue Oct 30, 2016 · 5 comments
Closed

[Android] File Creation Error: parent path may not exist #167

ksegla opened this issue Oct 30, 2016 · 5 comments
Labels

Comments

@ksegla
Copy link

ksegla commented Oct 30, 2016

Hi
Thanks for the much needed module. I'm trying to make it work but I'm having
"create file error: failed to create file at path " + path + " for its parent path may not exists"
path being /data/data/my_app_package/files/test.txt

/storage/emulated/0/data/data does exist and I even manually created the directory my_app_package to which I added directories files and cache.

Code:
const NEW_FILE_PATH = dirs.DocumentDir + '/test.txt';
const fs = RNFetchBlob.fs
fs.createFile(NEW_FILE_PATH, 'foo', 'utf8')

I followed the instructions, added external_storage access permission. Anything I missed?

RN: 0.34.1
RNFB: 0.9.6
Android: 5.0.2 (Samsung S6)

Thanks

@wkh237
Copy link
Owner

wkh237 commented Oct 31, 2016

@ksegla , thanks for reporting this issue. I think it's a misleading error message, I will make it more clear.

In this case, I think it throws an error due to the destination already has a file as such Android.File.createNewFile() abort this operation.

If you intended to overwrite the existing file, try fs.writeFile instead.

@ksegla
Copy link
Author

ksegla commented Oct 31, 2016

@wkh237 Thanks for the reply.

I just tried hard-coding /storage/emulated/0/logs (an existing directory that I used in a previous, unreleased, app of mine) and it worked! So it works with that directory but not with DocumentDirs

As DocumentDirs I have
/data/data/APP_PACKAGE/files
which I (may be wrongly) think translates to
/storage/emulated/0/data/data/APP_PACKAGE/files (/data does exist but I don't think it's usable)

To be clear, the file test.txt didn't exist before any of my attempts. Just the directory. It seems indeed though that there is a problem with the error message. When I try to create the DocumentDir (with an mkdir) before the createFile, it warns me that the directory exists already but then, just after, warns that createFile fails because the parent path may not exist.

Anyway, the fact that it works with my logs directory is already great for some experiments but it would be much better if I could make it work with the default dirs. Especially, for cross platform smoothness.

Do you have any idea what could cause this? I checked your code and the /data/data/APP_PACKAGE/ seems to come from the application context. I will double check android permissions and permissions on the directories.

PS: When there is a ( empty) file test.txt already and I use fs.writeFile, I don't have any warning, just nothing written in the file.

@lll000111
Copy link
Contributor

lll000111 commented Aug 16, 2017

For reference and documentation on this open issue, I think/hope I solved this particular error message issue in this PR: #489 This is related to my own isse #460 "Error normalization (ongoing, tracking)".

You can test once my PR is merged and 0.10.9 released, or from my own 0.10.9 repo branch at https://github.com/lll000111/react-native-fetch-blob/tree/0.10.9

I'll close this issue, feel free to reopen if the patch does not help .

@hzuhyb
Copy link

hzuhyb commented Sep 14, 2017

@lll000111 I also got the same problem, how to npm install [email protected]?

@lll000111
Copy link
Contributor

lll000111 commented Sep 14, 2017

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

No branches or pull requests

4 participants