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



72
73
74
# File 'lib/carrierwave/storage/grid_fs.rb', line 72

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



54
55
56
57
58
59
# File 'lib/carrierwave/storage/grid_fs.rb', line 54

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