开发者

where from does paperclip get the name of original file?

开发者 https://www.devze.com 2022-12-26 12:18 出处:网络
i started using nginx upload module (which creates upload files like /tmp/000121545) but i need paperclip to use original filename while saving files (like /public/avatars/LuckyLuke.jpg)

i started using nginx upload module (which creates upload files like /tmp/000121545) but i need paperclip to use original filename while saving files (like /public/avatars/LuckyLuke.jpg)

previously in the parameters Rails were passing just

 "avatar"=>#<File开发者_StackOverflow:/tmp/RackMultipart20100413-6151-t3ecq0-0> 

no original filename as well, so i am wondering where from does it come in paperclip? i tried looking through plugin code but it's currently a bit too complex for me.


The browser sends a http header with the file name. ("Content-Disposition: filename=original_file.jpg")

Rails makes this available as a instance method of the temp file object: params[:avatar].original_filename, and paperclip uses that.

In detail, Rack parses the multipart form in Rack::Utils::Multipart::UploadedFile and puts a hash in the parameters that includes :tempfile and :filename. Then ActionDispatch::Http::Upload comes along and replaces that hash by the File object (value of :tempfile), extending it with the module ActionDispatch::Http::UploadedFile, which adds a instance variable for original_path and the method original_filename.

0

精彩评论

暂无评论...
验证码 换一张
取 消