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

Read file from assets directory #75

Open
ShivamJoker opened this issue Oct 5, 2023 · 4 comments
Open

Read file from assets directory #75

ShivamJoker opened this issue Oct 5, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@ShivamJoker
Copy link

Feature
Right now I am not sure how can I read file which is in android\app\src\main\assets

Motivation
I have markdown file which I want to read and render.

@ShivamJoker ShivamJoker added the enhancement New feature or request label Oct 5, 2023
@alpha0010
Copy link
Owner

Here is an example of reading data from android assets: https://github.com/alpha0010/react-native-file-access/blob/v3.0.4/example/src/App.tsx#L31-L36 (targets this file).

@ShivamJoker
Copy link
Author

ShivamJoker commented Oct 9, 2023

Why do we need to copy the file every time I need to read it?

It would be great if we could directly read from the app res directory.

@alpha0010
Copy link
Owner

Main reason is I never needed to read assets in my projects, so I did not spend time programming it. For my projects, assets have been binary files (e.g. databases, images) unpacked to a specific location for other native code to handle; not any content I needed to see from JS side.

I am open to suggestions on how to make this easier to use. A difficulty is I would prefer to avoid bloating API by adding a bunch of xxAsset() functions to mirror the plain file functions. Any thoughts on how to augment the existing API to support referencing assets whenever used as a readonly file?

@ShivamJoker
Copy link
Author

ShivamJoker commented Oct 21, 2023

If possible it would be best to add the assets in the directory constants itself. Eg. Dirs.Assets.

Then we will be able to use all the existing APIs and we can remove cpAssets as well if we want.

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

No branches or pull requests

2 participants