Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
MongoMapper GridFS Attachment gem
Ruby
tag: 0.5.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
grip.gemspec

README.rdoc

grip

GridFS attachments for MongoMapper

installation

The grip gem is hosted on gemcutter.org:

  • gem install grip

Usage

class Foo
  include MongoMapper::Document
  include Grip

  has_grid_attachment :image, :versions => {:thumb => {:width=>50,:height=>50}}
  has_grid_attachment :pdf

  # Hook for resizing or whatever gets you there.
  # any specified options are passed back to you
  # at this point. 
  # Just return the file when you're done.
  def process_image opts
    puts "processing"
    opts[:file]
  end
end

image = File.open('foo.png', 'r')
pdf = File.open('foo.pdf', 'r')
foo = Foo.create(:image => image, :pdf => pdf)

foo.image # contents read from gridfs for serving from rack/metal/controller
foo.image_name # foo.jpg
foo.image_content_type # image/png
foo.image_size # File.size of the file
foo.image_path # path in grid fs foo/image/:id where :id is foo.id
Something went wrong with that request. Please try again.