next-s3-upload
next-s3-upload copied to clipboard
Support private buckets and getSignedUrl for uploaded images
Hey! Are you going to implement a way to provide support for private buckets and to implement a way to retrieve a signedUrl for the uploaded images?
Great question!
What would you like to see in terms of an API for generating signed URLs? Are you generating these URLs in API routes? gSSP? gSP? Would love to hear more about where you need them.
My apologies if this is not what @LorenzoGala meant, or if I misunderstand something
In the policy we add to our bucket, we basically make the complete bucket readable through getObject? I assume because that makes the url
property always be defined and valid? Haven’t tested this yet as I have been busy.
If so, would it be possible to generate a signed url for the Location so that we don’t need to allow getObject on our complete bucket?
Yup, that sounds right!
Right now the getting started guide is very basic, but it's not required if you want to use another approach. For example, you could change the policy and use signed urls that grant temporary access to files in your bucket.
I started working on a guide for how to best set up private uploads, but got a little busy with work. Hopefully I'll have something in a few weeks
That would be great @ryanto! Would you mind pointing me in the right direction on how to handle this? Some AWS docs would already be a great help.
We used this package source and converted it to work with Blitz for our project.
Sorry if i jump back in the conversation with a different account but i changed it for working reasons :)
After a bit of research i ended up using the next backend for the generation of pre-signed urls for the upload by creating a file in pages/api
called s3-upload-url.js
with the following code:
And then calling it in a component:
Of course this is a basic usage, can be improved but works fine!
PS: remember to setup a .env
file on the root of the project with the requested informations regarding the bucket!
Update: I've added an extra api for the generation of sharable presigned urls with expiration time setted to one week. In this way you can share the content of private buckets. You can find the code and more informations in my public boilerplate for Next.js: https://github.com/LorenzoGalassi/nextjs-boilerplate
@iDavidB @ryanto
Ok this is all set in version 0.2.6
. https://next-s3-upload.codingvalue.com/private-uploads
Thanks for paving the way @LorenzoGalassi