Rails, Getting a File's name when uploading a file to the server

旧时模样 提交于 2019-12-22 02:03:43

问题


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

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.

Any ideas?

Thanks


回答1:


params[:file].original_filename has the filename you are looking for.




回答2:


params[:name] should have the name of the attachment and params[:mime_type] which shows the mime type will be available in the params which u can use. Just to verify, you can use raise params.inspect like how Jamie Wong suggested.



来源:https://stackoverflow.com/questions/4002448/rails-getting-a-files-name-when-uploading-a-file-to-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!