Next.js Discord

Discord Forum

Best way to proxy an S3 image from Next.js backend?

Unanswered
Saltwater Crocodile posted this in #help-forum
Open in Discord
Saltwater CrocodileOP
I want to be able to upload files to AWS S3, and proxy those files to users without exposing S3.

I'm hosting Next.js in AWS and the specifics of the API interaction with S3 isn't an issue / question, but I'm wondering where / how I might best accomplish this from a Next.js perspective.

I'd like to be able to support images as well as PDFs.

I would like to keep image optimization as a feature of Next.js, e.g. using next/image on top of my proxy endpoint.

I thought perhaps I'd just make a /dam/[filename] route, but I'm wondering if there is a better / more "correct" way to do this.

1 Reply

Create a route that generate a presigned s3 url for the given id or path or whatever identifier you pass to it via a url arg