3

I need to display an Image component where the source is a URL that requires http headers passed on to fetch it (for authentication purposes).

How could this be implemented in RN?

Is there a way to add headers to the source?

1 Answer 1

3

This has been added to react-native. See here:

https://reactnative.dev/docs/images.html#network-requests-for-images

Example in link:

<Image
  source={{
    uri: 'https://reactjs.org/logo-og.png',
    method: 'POST',
    headers: {
      Pragma: 'no-cache',
    },
    body: 'Your Body goes here',
  }}
  style={{width: 400, height: 400}}
/>
Sign up to request clarification or add additional context in comments.

2 Comments

this works for me. But rather having static header, if I create a util function that returns the header this will not work. Do you have any idea ??
@Vasanth i am curious as well to get this working using a utility function. did you have any luck ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.