apache / cordova-plugin-file

Apache Cordova File Plugin
https://cordova.apache.org/
Apache License 2.0
741 stars 756 forks source link

cordova.file.dataDirectory returning wrong path #268

Closed niclarcipretti closed 3 years ago

niclarcipretti commented 5 years ago

Hi, Recently I tried to use the cordova.file.dataDirectory property to store/retrieve some files, but, in android, instead of the correct path "/data/data..." this returns me "/data/user/0...". Can anyone explain me why? And, if this is the expected behavior, how can I get the "/data/data/.."?

Cheers

Nikao

jcesarmobile commented 5 years ago

According to the README, I think it should be cordova.file.applicationStorageDirectory

newuser44 commented 5 years ago

I also can't seem to find where the file is download. I'm using file.dataDirectory It says the directory is file:///data/user/0/com.app.name/files/"

When I use a file manager I got to /storage/emulated/0/android/data/com.app.name/files and nothing is there.
Some how a file I download is corrupt. I can't download a new one until I delete the one one. I can't find it anywhere.

There is no way to have the files get download to the Download directory?

andreddosantos commented 5 years ago

I'm also experiencing this when asking for the "applicationStorageDirectory", i'm getting the

"/data/user/0..."

instead of

"/data/data..."

Why is this happening? Can someone help regards

GautierDele commented 5 years ago

Experiencing same problem here. I believe this issue label should be changed to bug.

jfoclpf commented 3 years ago

same issue here, apache is really ignoring this project which is full of bugs.

According to the README, I think it should be cordova.file.applicationStorageDirectory

no it shouldn't: image

dataDirectory should point to /data/data/<app-id>/files

Nonetheless

image

Any maintainer around from the project? Or is this suppose to get full of bugs?

breautek commented 3 years ago

/data/user/0 is symlinked to /data/data. They are the same directory.

generic_x86:/data/data/com.totalpave.iripg $ ls
app_database app_textures app_webview cache code_cache files shared_prefs 

generic_x86:/data/data/com.totalpave.iripg $ cd /data/user/0/com.totalpave.iripg

generic_x86:/data/user/0/com.totalpave.iripg $ ls
app_database app_textures app_webview cache code_cache files shared_prefs

The actual file paths may differ by android versions. Generally speaking, /data/user/0/ is used on android devices that supports multiple user accounts.

While the android docs is sparse, it does say:

Caution: The exact location of where your files can be saved might vary across devices. For this reason, don't use hard-coded file paths

For maximum compatibility, file paths shouldn't be hard-coded. Instead use the variables and concatenate relative paths to it.

I also can't seem to find where the file is download. I'm using file.dataDirectory It says the directory is file:///data/user/0/com.app.name/files/"

When I use a file manager I got to /storage/emulated/0/android/data/com.app.name/files and nothing is there. Some how a file I download is corrupt. I can't download a new one until I delete the one one. I can't find it anywhere.

There is no way to have the files get download to the Download directory?

This is the "external" data directory. That is, a directory that isn't private to the app. Files that are downloaded are generally placed in /storage/emulated/0/Download directory, although if the user was given a save dialog, they may have chosen a completely different directory. You can use the cordova.file.externalRootDirectory variable & concatenate the Download path to access this directory.

Closing as not-a-bug / won't fix.

jfoclpf commented 3 years ago

@breautek do you recommend me using any sort of path methods like in nodeJS, for example path.relative

breautek commented 3 years ago

@breautek do you recommend me using any sort of path methods like in nodeJS, for example path.relative

If you're asking for a recommendation, then not really. I've personally never had a need to seek out a robust pathing library. But I'm sure there are some that is available out there on NPM. If you use webpack@4, the node builin path library would also probably work.

jfoclpf commented 3 years ago

thank you @breautek indeed the paths in cordova are quite coherent. I'm just afraid of some trailing slash and since I work a lot in node, I really feel save by using path.join instead of +