Jackson
Jackson

Reputation: 6851

Saving a CSV into a blob

I would like to save CSV files that users upload to a blob. I would than like to retrieve the CSV file out of the blob in a format that I can use with the ruby CSV library. Any ideas on how I can accomplish that?

Upvotes: 2

Views: 3106

Answers (1)

DiegoSalazar
DiegoSalazar

Reputation: 13531

You'll have to add a field to your model with datatype :text (because that's what a CSV is, not binary). Let's say your model is called Record and the field is called csv:

record = Record.new
record.csv = File.read 'path/to/csv'
record.save
#... later...
CSV.parse record.csv # => here's your csv

Questions?

Upvotes: 1

Related Questions