0

Hi am trying to access image in assets/images/flower.png Am using react-native-fs but I tried different path but no luck. has anyone did this before and succeeded ?

var RNFS = require("react-native-fs");
this.base64RouteImage = await RNFS.readFile(
  "../../../assets/images/flower.png",
  "base64"
).then();
console.log("64 is " + base64data);

I tried below different path as below

/images/flower.png
app/assets/images/flower.png
/app/assets/images/flower.png
file://app/assets/images/flower.png
./assets/images/flower.png
import Flower from "../../../assets/images/flower.png";
../../../assets/images/flower.png

EDIT 1

I have added permission read/write internal/external permission in android

EDIT 2

I tried

RNFS.DocumentDirectoryPath + "/assets/images/flower.png" but it says

error: ENOENT: /data/user/0/com.tipll/files/assets/images/flower.png (No such file or directory)

I need to access the images in react-native assets folder app/assets/images/flower.png

enter image description here

Still no luck

EDIT 3

my path reference from my current screen is like ../../../assets/images/flower.png

EDIT 4

enter image description here

EDIT 5

Am trying to access image from app/views/routes/view/Flower.js this Flower.js screen.

Any help will be appreciated.

Thanks in advance

suja
  • 1,198
  • 2
  • 12
  • 32

2 Answers2

0

To Access data from internal memory: Filepath "/storage/emulated/0/".

To Access data from external memory(SD-CARD): Filepath "/storage/0000-0000/".

Few questions arise here,

1) How is the SD-CARD name "0000-0000"?

Well, 0000-0000 is Volume Serial Number, it changes every time an SD-CARD is formatted. If you want to regulate it i.e you want to add your own Serial Number, check out this post Change Serial Number.

2) How do you now what your SD-CARD Serial Number is?

You can use file managers in Playstore to know your SD-Cards Serial Number and also explore this discussion.

Ron Astle Lobo
  • 1,284
  • 2
  • 14
  • 34
0

If you want read from internal storage (of device) try this:

    file:///storage/emulated/0/Pictures/flower.jpg

I guess that you want read from a folder in your rn project... You must provide the structure of your project

So try with require('../../../assets/images/flower.png')

or try with absolute path: require('MyApp/app/assets/images/flower.png')

Bored
  • 499
  • 4
  • 11