Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload ActionDispatch::Http::UploadedFile To Amazon S3

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?):

like image 512
MichaelScaria Avatar asked Jul 29 '13 02:07

MichaelScaria


People also ask

How do I upload files to Amazon S3?

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.

Which HTTP code indicates a successful upload of an object to Amazon S3?

HTTP 200 code indicates a successful write to S3.

How do you upload the same name file to Amazon S3 and overwrite?

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.


1 Answers

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).

like image 154
MichaelScaria Avatar answered Oct 13 '22 13:10

MichaelScaria