Skip to content

Conversation

rahul1368
Copy link

Earlier we can't access the request.body, inside the key function, because if we use:
await request.json() , this causes error because this is already used inside handler.
So I have passed third optional parameter body to key function, because in order to make the S3 file key more dynamic , we can pass params in request body from the frontend.

await uploadToS3(file, { endpoint: { request: { url: "/api/v1/s3-upload", body: { bucket: "personal", }, }, }, });

So now , we will be able to access bucket value inside the key function from it's third parameter.

`async key(req: NextRequest, filename: string, body?: any){
    let fileKey = `${body.bucket}/${filename}`;
    ........
}`

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-s3-upload ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 10:35pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant