16

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

Jamie Wong
  • 18,104
  • 8
  • 63
  • 81
user479959
  • 507
  • 1
  • 8
  • 17
  • 1
    @user479959 Don't know offhand. Either dig through paperclip documentation or `raise params.inspect` and see if the filename is anywhere in there. – Jamie Wong Oct 23 '10 at 05:08

2 Answers2

34

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

cam
  • 14,192
  • 1
  • 44
  • 29
0

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.

Kunday
  • 1,041
  • 6
  • 9