alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
307 stars 19 forks source link

How to move files to phone storage #1

Closed Onibenjo closed 3 years ago

Onibenjo commented 3 years ago

Nice library, I noticed that Dirs only points to the apps storage on android and not the phone storage. Is there a way to move/copy files from the cache to the phone storage? or is this a bug?

Onibenjo commented 3 years ago

Ok, it is not a bug. Please any workaround around this?

alpha0010 commented 3 years ago

Dirs constant does not currently have paths (though internal code technically has no restrictions against access). Android is moving toward requiring MediaStore api for apps interacting with shared phone storage and I am uncertain how best to implement (without diverging too far from iOS if possible, ideally avoiding need for Platform.OS checks for apps using this library).

alpha0010 commented 3 years ago

Fixed in v0.6.0.

Onibenjo commented 3 years ago

Oh OK thanks

SaeedZhiany commented 2 years ago

@alpha0010

I didn't figure it out correctly, is it possible to work with Internal Storage in android by using your library? I need to store my files in the internal Storage so unroot devices will not be able to access my files.

does your library support both internal and external Storage utilities in Android?

if it's possible, which functions give me that utility?

Thanks

alpha0010 commented 2 years ago

@SaeedZhiany Sorry, I tend to miss comments on closed issues.

By default, this library uses internal storage. Prefix your path with one of the Dirs.* constants (with the exception of Dirs.SDCardDir).

To send data to external storage, you can use FileSystem.cpExternal() and to get from external storage use a content:// uri (as produced by, for example, react-native-document-picker) as the source parameter for a read call (e.g. FileSystem.cp()). Note that this gives you only limited control over how to interact with external storage, but that is necessary by Android security design. If you want to write anywhere you need the MANAGE_EXTERNAL_STORAGE permission, which will allow you to construct absolute paths yourself without needing to use a Dirs.* constant (/path/to/any/file.txt).