I am dealing with potentially huge CSV files which I want to export from my Rails app, and since it runs on Heroku, my idea was to stream these CSV files directly to S3 when gen
s3 = Aws::S3::Resource.new(region:'us-west-2')
obj = s3.bucket.object("#{FOLDER_NAME}/#{file_name}.csv")
file_csv = CSV.generate do |csv|
csv << ActionLog.column_names
ActionLog.all.each do |action_log|
csv << action_log.attributes.values
end
end
obj.put body: file_csv
file_csv = CSV.generate
is to create a string of CSV data in Ruby. After creating this string of CSV, we put to S3 using bucket, with the path
#{FOLDER_NAME}/#{file_name}.csv
In my code, I export all the data to an ActionLog
model.