question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storage does not work with Next.js image optimization ("url" parameter is valid but upstream response is invalid)

See original GitHub issue

Bug report

Describe the bug

Next.js provides a convenient way to handle image optimization. This also works for remote images. Unfortunately, Supabase Storage does not work with it at the moment.

When trying to use it, the response from Next.js will respond with "url" parameter is valid but upstream response is invalid.

To Reproduce

  1. Create a fresh Next.js project: npx create-next-app --use-npm
  2. Add a next.config.js in project root to add your Supabase project as a domain the Next.js will use for images:
module.exports = {
  images: {
    domains: ['your-app-id.supabase.co'],
  },
}

your-app-id is the one where the image is hosted in the Supabase Storage.

  1. Add an image component somewhere in your app:
import Image from 'next/image'
...
<Image
  src="https://your-app-id.supabase.co/storage/v1/object/avatars/public/your-file-name.jpg"
  alt="alt"
  width={500}
  height={500}
/>

For src, use the full path of the image. In my case, I use the getPublicUrl from the Storage API.

  1. npm run build
  2. npm run start

Looking at your browser’s dev tools, you can see the request for the image responds with status code 400 and "url" parameter is valid but upstream response is invalid.

Expected behavior

This error message is not unkown to Next.js, but it was fixed already. As other providers (you can e.g. try out an Imgur image) work fine, I assume this has something to do with how Supabase Storage handles these requests.

Screenshots

Request

image

Response

image

System information

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
thebengeucommented, Nov 10, 2021

@bennettdams Thanks for the suggestion! I agree that it’s counter-intuitive, added a note to the API of getPublicUrl().

0reactions
bennettdamscommented, Nov 9, 2021

@thebengeu @bnjmnt4n That was it! I had to make the bucket public via the UI.

I find it counter-intuitive that

  • even though the policy of the bucket allows public SELECT
  • and I use getPublicURL via an instanciated Supabase client (on the server)

…still was not enough for the image being available. Maybe this could be added to the API of getPublicURL?

Read more comments on GitHub >

github_iconTop Results From Across the Web

"url" parameter is valid but upstream response is invalid ...
Next image would return me my optimized image, not a 400 bad request with. "url" parameter is valid but upstream response is invalid....
Read more >
next js image component error "url" parameter is valid but ...
i was facing the same issue although i am hosting my images on cloudinary and it does work if i use the normal...
Read more >
"url" parameter is valid but upstream response is invalid - Reddit
My images are requested from my Strapi CMS but return the error: "url" parameter is valid but upstream response is invalid . To...
Read more >
next js image component error "url" parameter is valid but ...
Coding example for the question next js image component error "url" parameter is valid but upstream response is invalid-Reactjs.
Read more >
Next.js automatic image optimization with next/image
Learn about automatic image optimization and how it can benefit developers with the native, game-changing, and powerful next/image API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found