react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Unable to use local tmp file path for Image.source

Open mattotodd opened this issue 11 years ago • 10 comments

I am trying to use a local tmp file for the source of an Image and keep seeing error "Unrecognized tag protocol"

from the docs:

source {uri: string} uri is a string representing the resource identifier for the image, which could be an http address, a local >file path, or the name of a static image resource (which should be wrapped in the >required('image!name') function).

Have tried (giving the image explicit height and width)

<Image style={styles.thumb} source={{uri:"/var/mobile/Containers/Data/Application/5938C9F8-0A9D-40DD-AB9F-CD2C772439E7/tmp/thumbimage_8gVFD"}} />

<Image style={styles.thumb} source={{uri:"file:///var/mobile/Containers/Data/Application/5938C9F8-0A9D-40DD-AB9F-CD2C772439E7/tmp/thumbimage_8gVFD"}} />

<Image style={styles.thumb} source={require("image!"+"/var/mobile/Containers/Data/Application/5938C9F8-0A9D-40DD-AB9F-CD2C772439E7/tmp/thumbimage_8gVFD"} />

Loading web assets or static image resource works just fine.

mattotodd avatar Apr 08 '15 13:04 mattotodd

Found the answer, need to pass isStatic to the source of the image.

I feel this should be added to the Image docs

<Image style={styles.thumb} source={{isStatic:true, uri:"/var/mobile/Containers/Data/Application/5938C9F8-0A9D-40DD-AB9F-CD2C772439E7/tmp/thumbimage_8gVFD"}} />

mattotodd avatar Apr 08 '15 17:04 mattotodd

Would be nice indeed. Want to send a pull request?

vjeux avatar Apr 08 '15 17:04 vjeux

np

mattotodd avatar Apr 08 '15 17:04 mattotodd

How to avoid using absolute path for local file uri?

menway avatar Apr 22 '15 04:04 menway

isStatic didn't work for me... resorted to adding images into images.xcassets as described in the docs ... too bad it's not called images.xcasettes

idibidiart avatar Sep 29 '15 20:09 idibidiart

For anyone coming here looking to solve the android file loading issue, you need to put file:// in front of your file on android

PimDeWitte avatar Jul 11 '16 04:07 PimDeWitte

@idibidiart I know it's very late to comment over here, but this can help others in Future.

In my case tag must have

width and height in style property

isStatic : true in source property

to display image, otherwise it wan't visible.

vishalkakadiya avatar Oct 25 '16 08:10 vishalkakadiya

2018 now, using React Native 0.52 isStatic:true totally work! Thanks!

1c7 avatar Jan 21 '18 06:01 1c7

@vishalkakadiya thank you very much for this tip , the image started showing up as soon as i specified the height and the width property

jayasimhaprasad avatar Jan 28 '18 08:01 jayasimhaprasad

What worked for me on Android was a combination of many comments here:

  • isStatus: true
  • Prepend the file path with file://
  • Set the dimensions

caiosba avatar Apr 14 '18 02:04 caiosba