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

[Question] Loading an image saved to a path from RNFS #60

Closed
AlexDM0 opened this issue Mar 18, 2016 · 5 comments
Closed

[Question] Loading an image saved to a path from RNFS #60

AlexDM0 opened this issue Mar 18, 2016 · 5 comments

Comments

@AlexDM0
Copy link

AlexDM0 commented Mar 18, 2016

Hi,

I'm using gl-react-native and use their captureFrame method to save an image to file. I use RNFS to get the path for this file. If I lookup the path I can see that the image is there and can be reviewed using a normal image application.

However, when I want to require() it in an Image tag, I get the error that it cannot be resolved. The path is:
"file:///Users/alex/Library/Developer/CoreSimulator/Devices/6955A1DF-7189-4FD1-91EE-AFE106019086/data/Containers/Data/Application/F19A2400-3339-4C01-9FAA-FB36AE54C00E/Library/Caches/image.png"

Any idea why I cannot require this to show it as an image? I tried with and without the file://, I tried making it a relative path from the MainBundle path but none of them give me the image. Is there something obvious I'm overlooking?

It doesnt work on Android or iOS on either device or simulator.

(RN 0.21 if it matters)

Cheers

@mcorb
Copy link
Contributor

mcorb commented Mar 19, 2016

require() is a build-time directive for bundling resources with the application.

You should instead set the image source kind of like this:

self.setState({photoSource: {
uri: 'file://' + filePath,
//type: res.headers['content-type'],
//name: file.Name()
}});

There are examples linked in the tests project of RNFS.

Actually it'd be cool if RNFS had a utility function to conver a file path string into a source object like this for direct use with the react-native UI.

@AlexDM0
Copy link
Author

AlexDM0 commented Mar 19, 2016

Great thanks!

@AlexDM0
Copy link
Author

AlexDM0 commented Mar 21, 2016

I've searched this entire project for uri and looked through the code in the integration tests but I cant find the example you refer to. Is it another project? I did find the pull req for supporting file:// paths. Is that something required to get it working?

@AlexDM0
Copy link
Author

AlexDM0 commented Mar 21, 2016

Nevermind sorry, I found the test project and turns out I forgot to provide style information to the image.. Thanks for the help!

@adamgf
Copy link

adamgf commented Oct 28, 2018

require() is a build-time directive for bundling resources with the application.

You should instead set the image source kind of like this:

self.setState({photoSource: {
uri: 'file://' + filePath,
//type: res.headers['content-type'],
//name: file.Name()
}});

There are examples linked in the tests project of RNFS.

Actually it'd be cool if RNFS had a utility function to conver a file path string into a source object like this for direct use with the react-native UI.

How about a simple code example?

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

No branches or pull requests

4 participants