Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permit custom clientMethod for upload file #158

Merged
merged 2 commits into from
Mar 25, 2023

Conversation

Roriz
Copy link
Contributor

@Roriz Roriz commented Mar 20, 2023

if you're working with AWS S3, you may come across situations where you need to provide temporary access to S3 objects to users or services outside of AWS. In such cases, one of the best solutions is to use pre-signed URLs.

Pre-signed URLs are temporary URLs that grant time-limited access to specific S3 objects. They are signed with AWS credentials, allowing secure access to the objects without the need for the user to have AWS security credentials. To use pre-signed URLs for S3 file downloads or uploads, you'll need to generate the URL with specific parameters that define the permissions and expiration time. For example, if you want to allow a user to download a file from S3, you can generate a pre-signed URL with the "getObject" permission, a specific time limit, and the object key.

Similarly, if you want to allow a user to upload a file to S3, you can generate a pre-signed URL with the "putObject" permission, a specific time limit, and the bucket and object key where the file should be uploaded. Once the pre-signed URL is generated, you can provide it to the client application, who can then use it to perform the allowed operation (download or upload) on the S3 object within the time limit specified.

This means that your API server does not need to handle the I/O of transferring the file, which can be resource-intensive and slow down the server's response time. Instead, the user can directly interact with S3, improving performance and reducing the load on your API server.

More details about S3 signed url: https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html

Inspiration

A new version of Ruby on Rails has been recently released, which includes a new feature called "Direct Upload". This feature utilizes pre-signed URLs to enable easier uploading or sharing of backend files, with a full range of capabilities.
More info: https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads

@Roriz
Copy link
Contributor Author

Roriz commented Mar 20, 2023

I don't know how fix the unit tests, please help me with that

@etianen etianen merged commit 93a3566 into etianen:master Mar 25, 2023
@etianen
Copy link
Owner

etianen commented Mar 25, 2023

That's a nice implementation. I've tweaked it to add a settings check, and merged!

@etianen
Copy link
Owner

etianen commented Mar 25, 2023

The tests are broken because of a change in Amazon S3. This is unrelated to your change.

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.

None yet

2 participants