Class: CarrierWave::Storage::GridFS

Inherits:
Abstract show all
Defined in:
lib/carrierwave/storage/grid_fs.rb

Overview

The GridFS store uses MongoDB’s GridStore file storage system to store files

Defined Under Namespace

Classes: File

Instance Attribute Summary

Attributes inherited from Abstract

#uploader

Instance Method Summary collapse

Methods inherited from Abstract

#identifier, #initialize

Constructor Details

This class inherits a constructor from CarrierWave::Storage::Abstract

Instance Method Details

#retrieve!(identifier) ⇒ Object

Retrieve the file from MongoDB’s GridFS GridStore

Parameters

identifier (String)

the filename of the file

Returns

CarrierWave::Storage::GridFS::File

a sanitized file



76
77
78
# File 'lib/carrierwave/storage/grid_fs.rb', line 76

def retrieve!(identifier)
  CarrierWave::Storage::GridFS::File.new(uploader, database, uploader.store_path(identifier))
end

#store!(file) ⇒ Object

Store the file in MongoDB’s GridFS GridStore

Parameters

file (CarrierWave::SanitizedFile)

the file to store

Returns

CarrierWave::SanitizedFile

a sanitized file



58
59
60
61
62
63
# File 'lib/carrierwave/storage/grid_fs.rb', line 58

def store!(file)
  ::GridFS::GridStore.open(database, uploader.store_path, 'w', :content_type => file.content_type) do |f|
    f.write file.read
  end
  CarrierWave::Storage::GridFS::File.new(uploader, database, uploader.store_path)
end