Image not loading in react native having bearer token authentication

Viewed 231

I am having my images on a secure server. For authentication, I should provide a bearer token. If I pass it using the below format I am getting a blank image.

<Image
source={
{ uri: 'https://yourdomain.com/get-image',
  headers: {
            Authorization: 'Bearer xyz'
           }
        }
 }/>

When I have checked error code onError prop in Image source it has

"nativeEvent": {"error": "Unexpected HTTP code 403"}

I have tested the request in postman it is working without any issues.(I am able to see the image)

The token is valid.

Edit1: Sending an XMLHttpRequest and taking the byte array and converting it into Base64 works just fine.

1 Answers

"nativeEvent": {"error": "Unexpected HTTP code 403"}

The 403 error HTTP status code meaning access to the requested resource is forbidden for some reason.

I think your token bearer is not correct

Related