Chris Muench
Chris Muench

Reputation: 18318

Get file upload as string (Ruby on rails)

<h4>Upload CSV File:</h4> 
<%= form_tag(import_patients_path, :method =>'post', :multipart => true) %>
<%= file_field_tag 'csvfile' %>
<br />
<%= submit_tag "Upload CSV Data" %>
</form>

From the controller I simply need to get the file as a string. Is there an easy way to do this? (I don't need to save the file anywhere)

Upvotes: 4

Views: 1720

Answers (1)

jonnii
jonnii

Reputation: 28312

You can do something like:

csv_data = params[:uploaded_file].read

Upvotes: 5

Related Questions