paperclip从哪里获取原始文件的名称?

时间:2022-08-08 16:59:21

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)

我开始使用nginx上传模块(创建上传文件,如/ tmp / 000121545)但我需要回形针在保存文件时使用原始文件名(如/public/avatars/LuckyLuke.jpg)

previously in the parameters Rails were passing just

以前在参数Rails传递的只是

 "avatar"=>#<File:/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.

没有原始文件名,所以我想知道它在哪里来回形针?我尝试通过插件代码查看,但它对我来说目前有点过于复杂。

1 个解决方案

#1


19  

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

浏览器发送带有文件名的http标头。 (“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.

Rails使其可用作临时文件对象的实例方法:params [:avatar] .original_filename,paperclip使用它。

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.

详细地说,Rack在Rack :: Utils :: Multipart :: UploadedFile中解析multipart表单,并在参数中放入一个哈希值,包括:tempfile和:filename。然后ActionDispatch :: Http :: Upload出现并用File对象替换该哈希值(值:tempfile),用模块ActionDispatch :: Http :: UploadedFile扩展它,它为original_path和方法original_filename添加一个实例变量。

#1


19  

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

浏览器发送带有文件名的http标头。 (“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.

Rails使其可用作临时文件对象的实例方法:params [:avatar] .original_filename,paperclip使用它。

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.

详细地说,Rack在Rack :: Utils :: Multipart :: UploadedFile中解析multipart表单,并在参数中放入一个哈希值,包括:tempfile和:filename。然后ActionDispatch :: Http :: Upload出现并用File对象替换该哈希值(值:tempfile),用模块ActionDispatch :: Http :: UploadedFile扩展它,它为original_path和方法original_filename添加一个实例变量。