9

i am fetching data from tmdb api .But the image doesn't load so i open the image in the new tab .then it shows

"url" parameter is valid but upstream response is invalid so how to resolve the issue

Hunter003
  • 97
  • 1
  • 1
  • 3

4 Answers4

3

Have you added the domain of the images to the next config ?

below is an example:

//next.config.js
module.exports = {
  reactStrictMode: true,
  webp: {
    preset: "default",
    quality: 100,
  },
  images: {
    domains: ["randomuser.me", "firebasestorage.googleapis.com"],
  },
  //Internationalization
  i18n: {
    locales: ["en", "it"],
    defaultLocale: "en",
  },
};
Appy Mango
  • 1,298
  • 5
  • 16
  • From the [NextJS documentation](https://nextjs.org/docs/pages/api-reference/components/image-legacy#domains): "We recommend configuring strict `remotePatterns` instead of `domains` in order to protect your application from malicious users. Only use domains if you own all the content served from the domain." – idleberg Jun 05 '23 at 09:37
1

What it worked in my case, was to do a clean reload of browser.

In Chrome, it is CTRL + SHIFT + R

Gabriel Arghire
  • 1,992
  • 1
  • 21
  • 34
0

i was facing the same issue although i am hosting my images on cloudinary and it does work if i use the normal <img/> tag so i changed the nextjs version on package.json as bellow and it worked just fine: hope it woud work for u as well

 "dependencies": {
   ...
  "next": "11.0.1",
   ...

 }
Alii Isk
  • 82
  • 1
  • 9
0

I had forgotten to add the X-Forwaded-For and X-Real-IP headers in nginx which caused an issue with image domains i had specified in next.config.js

If you are serving with http

    location / {
        proxy_set_header Host            $host;
        proxy_set_header X-Real-IP       $proxy_protocol_addr;
        proxy_set_header X-Forwarded-For $proxy_protocol_addr;
        proxy_pass  http://somehost:port;                                                                               
    } 

If you are serving with uWSGI check you are including the params file as per https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configure-nginx-for-your-site

Sam Duff
  • 121
  • 1
  • 3