Search code examples
ruby-on-railsamazon-s3file-uploadrails-activestorage

How to implement AWS S3 Multipart Upload with Rails and Active Storage?


I'm using vanilla Rails Active Storage file upload with multiple:true option. The files are stored on S3. The setup is working well. However, I was thinking for very large files it would be beneficial to implement Multipart Upload for optimal speed and reliability.

I found a description of AWS S3 multipart upload here: https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html

I also found a Ruby specific page: https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu-ruby-sdk.html

However, I couldn't find any reference on how to implement this feature with Rails and Active Storage.

I would like to receive some direction on how best to go about implementing multipart upload without ripping out Active Storage if possible.


Solution

  • In case somebody is looking for an answer on this. Active Storage will support multipart upload starting from Rails 6.1. Active Storage direct upload automatically switches to multipart for large files. No settings changes are required.

    You can customise the threshold for what is considered a large file. The default is 100MB, and you can change the default by adding this to your storage.yml under the amazon settings: upload: multipart_threshold: <%= 250.megabytes %>

    Reference: https://github.com/rails/rails/blob/master/activestorage/CHANGELOG.md