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

Adding Dynamic bucket & region params to config

Open DhenPadilla opened this issue 1 year ago • 10 comments

Context

We're using Next-s3-upload to upload to a single bucket currently. This sufficed for a single use case up until now as we have a strong security requirement to keep the current bucket that we're uploading to be completely READ-restricted to public access (i.e private to anything external to aws). This cannot change.

We want to continue using next-s3-upload for our new use case: Uploading files to a new bucket which would have public read access. Currently, next-s3-upload does not allow for dynamically allocating a bucket name and only saves to the S3_UPLOAD_BUCKET env var. This is fine for our initial use case, but definitely not moving forward as we may need more than 2 buckets but especially more than 1.

Note: Although we're using 1 region, I imagine we (or other users) may use multiple regions now in the future.

I imagine this would help other users of the package, so hopefully this is a solid PR!

DhenPadilla avatar Oct 28 '23 17:10 DhenPadilla

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

Name Status Preview Comments Updated (UTC)
next-s3-upload ❌ Failed (Inspect) Oct 30, 2023 2:45am

vercel[bot] avatar Oct 28 '23 17:10 vercel[bot]

Cool, thanks for the PR!

I'd like to understand this a little better... can you show me how'd you use this with code? Do you have if statements inside your bucket function?

ryanto avatar Oct 28 '23 18:10 ryanto

@ryanto

No worries! Of course, Here's a snippet of how I intend to use this:

async bucket(req) {
    const { uploadType } = req.body as { uploadType: S3UploadType }
    const bucketName =
        uploadType === S3UploadType.image
            ? process.env.S3_PUBLIC_BUCKET
            : process.env.S3_PRIVATE_BUCKET
            
    // May extend to more options in the future 
    return bucketName
}

Omitting S3UploadType type from the code here as it would be 1st-party

DhenPadilla avatar Oct 28 '23 18:10 DhenPadilla

Ok cool , makes sense! I'll probably need a few days before I can get this merged and published.

One thing that would help speed things up is if you could add docs to this page: https://next-s3-upload.codingvalue.com/bucket-config

ryanto avatar Oct 29 '23 21:10 ryanto

Ok cool , makes sense! I'll probably need a few days before I can get this merged and published.

One thing that would help speed things up is if you could add docs to this page: https://next-s3-upload.codingvalue.com/bucket-config

Yep! Done!

DhenPadilla avatar Oct 30 '23 02:10 DhenPadilla

@ryanto Would be amazing to have this in soon as I do need this build for this week if possible! :')

DhenPadilla avatar Oct 30 '23 17:10 DhenPadilla

Bumping this when possible!

DhenPadilla avatar Nov 17 '23 03:11 DhenPadilla

Bumping this too, my team would benefit from dynamic bucket functionality as we're storing data in both a public and private bucket.

Great work here @DhenPadilla. Sorry to spam but a merge would be great @ryanto 🙏

anthonykrivonos avatar Dec 03 '23 22:12 anthonykrivonos

@DhenPadilla Thanks for your blessed contribution. We couldn't wait any longer so we created a fork with your changes.

yarn add @toma.so/next-s3-upload

anthonykrivonos avatar Jan 16 '24 06:01 anthonykrivonos