Skip to content

Images with Headers Authentication are not showing.  #30017

Closed as not planned
Closed as not planned

Description

@Biplovkumar

Description

I am showing headers Auth Images via 'GET method but some images are showing fine and some are not.
in IOS & Android not showing.
The onLoadEnd method also calling fine but still image not showing.
I am Stuck in the last 5 Days.
I think some images are late coming from the URL so maybe the Image tag doing timeOut.

React Native version:

    "react": "16.13.1",
    "react-native": "0.63.2",

System:
OS: macOS 10.15.6
CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Memory: 87.70 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.0. - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3
System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Intel x86 Atom_64, android-Q | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 12.0/12A7209 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_221 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
react-native-macos: Not Found

Steps To Reproduce

  1. Added Image tag
  2. Passed URL Link and Authentication too but in 100 images some of the images are showing and some of the images are not showing.

Expected Results

All Images Need to show fine.

Snack, code example, screenshot, or link to a repository:

<Image style={{width: 200, height: 200}} source={{uri: ImgURL, headers: {Authorization : 'OAuth 0000000000', },}} onLoadEnd={()=>{console.log("Loaded")}} />

Activity

  1. Biplovkumar commented on Sep 24, 2020

    @Biplovkumar
    Author

    @admin plz help .

  2. jeswinsimon commented on Sep 26, 2020

    @jeswinsimon
    Contributor

    Since there are 100 images it is not easy for others to do a repro. Could you try someone debugging and find a similarity between the images that are not loading. Check loading the images using curl or postman to check if the url's are valid. Check the size or file to see if there is any similarity. More information would be helpful to troubleshoot this issue.

  3. Biplovkumar commented on Oct 1, 2020

    @Biplovkumar
    Author

    Those Images are showing in postman. But not in our app.
    Just create min 10 images with authentication, which is less size.
    Then you will be able to regenerate the issue.
    @jeswinsimon .
    Thanks for the reply.

  4. kylerc commented on Oct 3, 2020

    @kylerc

    I've also been running into this issue. It seems like #25945 might be an older issue for this same thing that was closed, but never actually resolved. It seems like on android only, that image headers either don't send, or don't send in all conditions resulting in the image not being able to render.

  5. fairlycasual commented on Oct 14, 2020

    @fairlycasual

    Same issue here after upgrading to 0.63.3 from 0.61.4, on Android only.
    For reference, the image component appears to be stripping off our Headers (containing Authorization token, and Correlation ID) when the request leaves. Our current implementation for accessing photo resources relies on a call to our Photos service api that provides a 307 response redirect to an external storage url for photos. We have implemented a work-around that pre-fetches the redirect url using Axios interceptors, and then passes this url along to the image component as that url does not require any headers or authorization.

  6. rastuch commented on Dec 24, 2020

    @rastuch

    sames here, i trying get image from remote url with auth headers and sometimes is just not working. In onError props i have nativeEvent.error with status code 401, but when i was debugging it turns out that image server do not have any request from mobile app. When i change the url to without auth, the image was downoload.

  7. bnap00 commented on Apr 29, 2021

    @bnap00

    same issue

  8. asaadawey commented on Aug 5, 2021

    @asaadawey

    any news ?
    same here

  9. odyRafaelM commented on Nov 3, 2021

    @odyRafaelM

    This is an ongoing issue, headers are not being sent.

  10. marcesengel commented on Jan 10, 2022

    @marcesengel
    Contributor

    Hello,

    I'm currently looking into this issue. It seems to be located in com.facebook.react.views.imagehelper.MultiSourceHelper.MultiSourceResult, as I can only reproduce it when passing multiple sources. When I temporarily cut down the list to a length of 1, the image will be loaded (and thereby the cache populated). After that it will show at least the cached image, even when switching back to multiple sources, as this is loaded here
    https://github.com/facebook/react-native/blob/6be46b0bb59f2d88bc78e9a72db672bd55914fa7/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java#L662-L666

    The temporary fix is to only pass lists of length 1 on Android.

    I will update this as soon as I have fixed the issue or at least found the root cause in case I can't go ahead and fix it.

    Edit: I just now realised this issue was about single pictures, I guess I should open a new issue for this.

  11. NilsBaumgartner1994 commented on Dec 7, 2022

    @NilsBaumgartner1994

    having still the problem

  12. donatoferrulli commented on May 4, 2023

    @donatoferrulli

    any news ?

  13. ameyarumbleon commented on Aug 11, 2023

    @ameyarumbleon

    any updates?

  14. nathanael-e commented on Sep 4, 2023

    @nathanael-e

    I also encounterd this problem.

    A workaround, if possible, is to include the token as a query string instead.

  15. github-actions commented on Mar 2, 2024

    @github-actions

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  16. added
    Stale
    on Mar 2, 2024
  17. NilsBaumgartner1994 commented on Mar 2, 2024

    @NilsBaumgartner1994

    Any updates on this?

  18. removed
    Stale
    on Mar 3, 2024
  19. react-native-bot commented on Aug 30, 2024

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  20. added
    Stale
    on Aug 30, 2024
  21. react-native-bot commented on Sep 6, 2024

    @react-native-bot
    Collaborator

    This issue was closed because it has been stalled for 7 days with no activity.

  22. MomenMustafa45 commented on Nov 22, 2026

    @MomenMustafa45

    Description

    I am showing headers Auth Images via 'GET method but some images are showing fine and some are not. in IOS & Android not showing. The onLoadEnd method also calling fine but still image not showing. I am Stuck in the last 5 Days. I think some images are late coming from the URL so maybe the Image tag doing timeOut.

    React Native version:

        "react": "16.13.1",
        "react-native": "0.63.2",
    

    System: OS: macOS 10.15.6 CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz Memory: 87.70 MB / 8.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.18.3 - /usr/local/bin/node Yarn: 1.22.4 - ~/.yarn/bin/yarn npm: 6.14.6 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.0. - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0 Android SDK: API Levels: 28, 29 Build Tools: 28.0.3, 29.0.2, 29.0.3 System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Intel x86 Atom_64, android-Q | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 12.0/12A7209 - /usr/bin/xcodebuild Languages: Java: 1.8.0_221 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.2 => 0.63.2 react-native-macos: Not Found

    Steps To Reproduce

    1. Added Image tag
    2. Passed URL Link and Authentication too but in 100 images some of the images are showing and some of the images are not showing.

    Expected Results

    All Images Need to show fine.

    Snack, code example, screenshot, or link to a repository:

    <Image style={{width: 200, height: 200}} source={{uri: ImgURL, headers: {Authorization : 'OAuth 0000000000', },}} onLoadEnd={()=>{console.log("Loaded")}} />

    For anyone still hitting this on Android, I traced it to Image.android.js (checked on RN 0.86.2, New Architecture).

    node_modules/react-native/Libraries/Image/Image.android.js, around lines 201–228:

    if (Array.isArray(source_)) {
      const { headers: sourceHeaders, width: sourceWidth, height: sourceHeight } = source_[0];
      if (sourceHeaders != null) {
        nativeProps.headers = sourceHeaders; // <- headers only forwarded here
      }
      // ...
      nativeProps.source = source_;
    } else {
      const { uri, width: sourceWidth, height: sourceHeight } = source_;
      // ...
      nativeProps.source = [source_]; // <- wrapped in an array, but `headers` is never set
    }

    On Android, headers reach the native image view only through the separate headers prop. ReactImageView.setSource() reads just uri, cache, width and height from each source and ignores any headers inside it. That prop is only set in the Array.isArray(source_) branch, so the common form

    <Image source={{ uri, headers: { Authorization: `Bearer ${token}` } }} />

    goes through the else branch: the headers are silently dropped and the request goes out without them (401 in our case). iOS isn't affected because it reads headers from inside each source.

    Workaround: pass the source as an array:

    <Image source={[{ uri, headers: { Authorization: `Bearer ${token}` } }]} />

    Possible fix: forward the headers in the else branch too:

    const { uri, headers: sourceHeaders, width: sourceWidth, height: sourceHeight } = source_;
    if (sourceHeaders != null) {
      nativeProps.headers = sourceHeaders;
    }

    Note this is separate from the redirect case mentioned above. If your server answers with a redirect to another host, the HTTP client on Android (OkHttp) drops Authorization on its own, so passing a pre-resolved or signed URL is still the fix there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ImageNeeds: Triage 🔍Stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions