NoMethodError in UploadsController#create
undefined method `write' for #<Aws::S3::Object:0x007ff0981bb850>
Código
# Upload the file obj.write( file: params[:file], acl: :public_read )
Este es mi código:
Código
class UploadsController < ApplicationController def new end def create # Make an object in your bucket for your upload obj = S3_BUCKET.object(params[:file].original_filename) # Upload the file obj.write( file: params[:file], acl: :public_read ) # Create an object for the upload @upload = Upload.new( url: obj.public_url, name: obj.key ) # Save the upload if @upload.save redirect_to uploads_path, success: 'File successfully uploaded' else flash.now[:notice] = 'There was an error' render :new end end def index @uploads = Upload.all end end
Estoy usando la versión 2 de aws-sdk, pero al parecer si está bien:
Porque esto es lo que me trae:
Código:
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"KNpjxo3vZBXKpno9JVGJXu69fxBpwjNdfY8p1f9fleaaecfk3I7avRk42v5FqKwIqMS6puX2Qm9GJhrn5rCB+w==",
"file"=>
#<ActionDispatch::Http::UploadedFile:0x007ff0a8030890
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"file\"; filename=\"lake-louise-alberta.jpg\"\r\nContent-Type: image/jpeg\r\n",
@original_filename="lake-louise-alberta.jpg",
@tempfile=#<File:/tmp/RackMultipart20170815-9057-16b57sd.jpg>>,
"commit"=>"Upload file"}
Saludos!!