Rails,将文件上传到服务器时获取文件名 [英] Rails, Getting a File's name when uploading a file to the server
本文介绍了Rails,将文件上传到服务器时获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Rails 3 中使用 AJAX 上传器和 paper_clip 并在此处上传文件:
I'm using an AJAX uploader in Rails 3, along with paper_clip and have files uploading here:
def upload
@photo = Photo.create({ :photo => params[:file], :title => params[:filename] })
respond_to do |format|
format.json
end
end
我想将照片的标题设置为照片的文件名,但不知道如何设置,即使 params[:file] 确实有该文件并且正在上传到 S3.
I want to set the photo's title as the photo's filename, but don't know how to, even though params[:file] does have the file and is being uploaded to S3.
有什么想法吗?
谢谢
推荐答案
params[:file].original_filename
包含您要查找的文件名.
params[:file].original_filename
has the filename you are looking for.
这篇关于Rails,将文件上传到服务器时获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文