next-s3-upload icon indicating copy to clipboard operation
next-s3-upload copied to clipboard

Support private buckets and getSignedUrl for uploaded images

Open LorenzoGala opened this issue 2 years ago • 6 comments

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?

LorenzoGala avatar Apr 28 '22 15:04 LorenzoGala

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.

ryanto avatar Apr 28 '22 22:04 ryanto

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?

dbrxnds avatar Jun 07 '22 22:06 dbrxnds

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

ryanto avatar Jun 08 '22 01:06 ryanto

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.

dbrxnds avatar Jun 08 '22 06:06 dbrxnds

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: raycast-untitled

And then calling it in a component: raycast-untitled (5)

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!

LorenzoGalassi avatar Jun 08 '22 06:06 LorenzoGalassi

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

LorenzoGalassi avatar Jun 18 '22 14:06 LorenzoGalassi

Ok this is all set in version 0.2.6. https://next-s3-upload.codingvalue.com/private-uploads

Thanks for paving the way @LorenzoGalassi

ryanto avatar Nov 29 '22 14:11 ryanto