Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 401
user479959 Avatar asked Oct 23 '10 04:10

user479959


1 Answers

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

like image 56
cam Avatar answered Oct 17 '22 07:10

cam