How can I upload a ActionDispatch::Http::UploadedFile
to Amazon S3?
@file_data = params[:upload][:file]
s3 = AWS::S3.new
obj = s3.buckets['WeMake'].objects.create("video", file)
I then get this error: ArgumentError (:data must be provided as a String, Pathname, File, or an object that responds to #read and #eof?):
In the Amazon S3 console, choose the bucket where you want to upload an object, choose Upload, and then choose Add Files. In the file selection dialog box, find the file that you want to upload, choose it, choose Open, and then choose Start Upload. You can watch the progress of the upload in the Transfer pane.
HTTP 200 code indicates a successful write to S3.
By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.
I needed to access the actual file, params[:upload][:file].tempfile
and add a file extension to the s3 upload, obj = s3.buckets['Bucket'].objects.create("video.mov", @file_data.tempfile)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With