1
votes

I'm currently using Carrierwave and want to be able to save the original filename as my model Document's title. I see that when I submit the document uploader form, the filename is saved as @original_filename.

How would I access this? I tried params[:document][:attachment][:original_filename] , but the "@" is what's confusing me.

Also, the main reason why I want to save the filename as a hard title is because if I use Document.attachment.file.filename, it sometimes shows as "6sw=&Expires=1409522546" instead of the filename, probably because of the random extensions that get added when the file gets uploaded to S3

Parameters:

{"utf8"=>"✓", "authenticity_token"=>"f67R1N2JR0b4WDWeYfSzI8q3DKwK59y487TXhR4xYvo=", "document"=>{"attachment"=>#, @original_filename="1 documents.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"document[attachment]\"; filename=\"1 documents.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Upload Files"}

1

1 Answers

3
votes

params[:document][:attachment] returns an object that encapsulates the uploaded file. So I think this will work:

uploaded_file = params[:document][:attachment]
uploaded_file.original_filename # => returns the file name