Hello Guys, After a long time I am back with the solution of large file uploads hassle on s3. Many times we face problem in uploading large files to S3. When we try to upload large file to S3, it become more difficult than usual. Here is step by step demonstration how we can upload large files on S3:
What is multipart upload?
Before we go on for multipart upload, we should know about it first.
S3 has a
multipart_threshold defined, the default value of it is
16777216 Bytes or
16.777216MB. When uploading file size exceeded this threshold S3 assume it as multipart upload.
Override File method
First you have to override the File class and create a method that returns the part of the file of given size. Here is the code
You can create a new class or just a method to perform upload action. In this example I am using a method to upload.
The above method will check for the large file. If the file size exceeded
multipart_threshold. Then multipart upload will be perform, normal write will be perform otherwise.
upload_large_file_to_s3 method return the
public url of the uploaded file if successful upload is completed.
My recommendations is to use sidekiq or any background processing to handle large file upload to avoid requst time out.
Hope It will solve your problem. If you still facing problem or you have other version of the gem you can follow this link For more detail.
Email : email@example.com
Website : https://ramlaxman.co.in