etianen / django-s3-storage

Django Amazon S3 file storage.
BSD 3-Clause "New" or "Revised" License
412 stars 94 forks source link

feat: permit custom clientMethod for upload file #158

Closed Roriz closed 1 year ago

Roriz commented 1 year ago

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 commented 1 year ago

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

etianen commented 1 year ago

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

etianen commented 1 year ago

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