21

My image-source is secured, so ideally I would like to do the following:

<Image source={{uri: "http://path/to/image", 
                headers: {Authorization: 'Bearer ' + this.props.bearerToken}}}/> 

Is there anyway I can approximate that, short of loading the image into Javascript and rendering the image from there?

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
  • I understand this question is pretty dated at this point, but I came upon it while searching for an answer and yes, you can. It's implemented to work exactly how you have it formatted in your question, although you'd have to account for whether http is correct vs https depending on other factors. https://reactnative.dev/docs/image#imagesource – Dwigt May 02 '22 at 19:44

3 Answers3

25

React Native supports adding header or body in requesting image. UPDATED: See this.

 <Image source={{
      uri: 'https://facebook.github.io/react/img/logo_og.png',
      method: 'POST',
      headers: {
        Pragma: 'no-cache'
      },
      body: 'Your Body goes here'
    }}
    style={{width: 400, height: 400}} />
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
Aung Myat Hein
  • 4,018
  • 1
  • 36
  • 42
6

This capability has recently been merged into React-Native: https://github.com/facebook/react-native/pull/7338/files

Shaheen Ghiassy
  • 7,397
  • 3
  • 40
  • 40
  • this is promising, however as of the moment of this comment, android feature is not merged, https://github.com/facebook/react-native/pull/7791 – Oscar Franco Aug 08 '16 at 23:02
1

I have this problem before, but Image component does not support this feature right now.

You may try react-native-fetch-blob to get BASE64 string of the image url and set its source this way

    <Image source={{uri : BASE64_IMAGE_STRING}}/>
Xeijp
  • 853
  • 1
  • 7
  • 18