mardi 5 mai 2015

From ActiveRecord to S3

I am new to S3 and Rails so got stuck. I am wondering if I can directly pass object to S3.

My controller:

def start_upload
  @forecasts = Forecast.all
  Forecast.export_to_s3(@forecasts) 
end

Model:

def self.export_to_s3(data)
  ---AWS configs ---
  Aws.config = { :access_key_id => aws_access_key, :secret_access_key => aws_secret_access_key, :region => aws_region }

  s3 = Aws::S3::Client.new(region:aws_region)

   resp = s3.put_object(
     :bucket => aws_bucket,
     :key => aws_bucket_key_forcast,
     :body => IO.read(data)
   )
end

Aucun commentaire:

Enregistrer un commentaire