feat: permit custom clientMethod for upload file #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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