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

Setting the Image Source Using RNFetchBlob #504

Closed
@GenericJam

Description

@GenericJam

I don't know if this is an issue with React Native or with RNFetchBlob.
I'm taking a picture and I want to show it to the user so they can verify they want that image to upload to the server.

The file is accessible by RNFetchBlob and I can verify it is there using fs.exists, so RNFetchBlob recognizes it. Then when I try to put it into an <Image> either by source={require(imageSource)} or source={{uri: imageSource}}, it fails.

If I use require it fails with the error: Unknown named module: '/data/user/0/com.myapp/files/photo.jpg'.

To save the file:

var imageLocation = urljoin(RNFetchBlob.fs.dirs.DocumentDir,  'photo.jpg');

RNFetchBlob.fs.writeFile(imageLocation, RNFetchBlob.base64.encode(data), 'base64')
.then(() => {
     console.log('Picture saved to ' + imageLocation);
     this.setState({pictureLocation: imageLocation});
});

To show it later:

<Image source={require(this.state.pictureLocation)} style={{width:200, height:200}} />`

I've tried it with and without 'file://' at the beginning of the image path as well as RNFetchBlob.wrap().

This is on Android.

I've gone over this many times backward and forward and I can't figure it out. Any ideas what I'm doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions