Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the filename from this ActionDispatch

When I upload a file and request the following params:

params[:product][:images_attributes]["0"][:image]

it returns:

#<ActionDispatch::Http::UploadedFile:0x007fcbe5c8f768 @original_filename="motorized-bicycle-9.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"product[images_attributes][0][image]\"; filename=\"motorized-bicycle-9.jpeg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/qf/gjxv0pl142scx9131j0k65_00000gs/T/RackMultipart20140328-969-12np4s4>>

What is the ruby code that I would use to get the filename?

like image 306
Snubber Avatar asked Mar 28 '14 18:03

Snubber


1 Answers

Try this:

params[:product][:images_attributes]["0"][:image].original_filename

#original_filename should be the name of the file that the user uploaded, from the documentation on ActionDispatch::Http::UploadedFile.

like image 121
Sandy W Avatar answered Oct 30 '22 14:10

Sandy W