Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJs image optimization not working in Vercel production (400: BAD_REQUEST) with @payloadcms/storage-uploadthing #6600

Closed
poofy25 opened this issue Jun 3, 2024 · 3 comments
Assignees
Labels

Comments

@poofy25
Copy link

poofy25 commented Jun 3, 2024

Link to reproduction

No response

Payload Version

3.0.0-beta.36

Node Version

v21.4.0

Next.js Version

15.0.0-rc.0

Describe the Bug

I can't fetch images from the local api and display them in an component

In dev mode everything works fine
{ ... "url": "/api/media/file/137-92091.jpeg", ... }
I get the url from the media collection files and then display it in the <Image/> component as follows

<Image className="h-full w-[50%] object-cover" src={blockData.image.url} alt="img" width="400" height="400" />

And it works just fine. The <img/> element then optimizes the image and returns this url
/_next/image?url=%2Fapi%2Fmedia%2Ffile%2F137-92091.jpeg&w=640&q=75
and it works just fine in development mode.

But when i deployed it to Vercel when going to https://starbucks-clone-orpin.vercel.app/api/media/file/137-92091.jpeg the image loads but when the <Image/> component optimizes the image with the following url :
/_next/image?url=%2Fapi%2Fmedia%2Ffile%2F137-92091.jpeg
it returns the following:
400: BAD_REQUEST Code: INVALID_IMAGE_OPTIMIZE_REQUEST ID: fra1::n89vt-1717417920074-c8806297edac

image
image

Reproduction Steps

Repository : https://github.com/poofy25/starbucks-clone

  1. Clone the repository

  2. Create .env file using the .env.example file

  3. Deploy to Vercel

Adapters and Plugins

@payloadcms/storage-uploadthing

@poofy25 poofy25 added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Jun 3, 2024
@laamdev
Copy link

laamdev commented Jun 4, 2024

I'm getting the same error when trying to display images in a Vercel deployment using a Supabase S3 bucket. Any solutions?

@poofy25
Copy link
Author

poofy25 commented Jun 5, 2024

I'm getting the same error when trying to display images in a Vercel deployment using a Supabase S3 bucket. Any solutions?

So i found a workaround for this issue all you gotta do is add the website url in the image src path
For example

Before:
<Image src={image.url} ...>

After
<Image src={${process.env.WEBSITE_URL}${image.url}} />

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jun 10, 2024
@jmikrut
Copy link
Member

jmikrut commented Jun 10, 2024

Hey all, yes, as @poofy25 said, on your frontend, I believe you need to pass full URLs to the next/image component. I will convert this to a Discussion so that we can continue to help there!

@payloadcms payloadcms locked and limited conversation to collaborators Jun 10, 2024
@jmikrut jmikrut converted this issue into discussion #6704 Jun 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants