如何从此ActionDispatch获取文件名
当我上传文件并请求以下参数时:
params[:product][:images_attributes]["0"][:image]
它返回:
#<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=#>
我将使用什么ruby代码来获取filename
?
试试这个:
params[:product][:images_attributes]["0"][:image].original_filename
#original_filename
应该是用户上传的文件的名称,来自ActionDispatch :: Http :: UploadedFile上的文档 。