Class: CarrierWave::Storage::File

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

Overview

File storage stores file to the Filesystem (surprising, no?). There’s really not much to it, it uses the store_dir defined on the uploader as the storage location. That’s pretty much it.

Instance Attribute Summary

Attributes inherited from Abstract

#uploader

Instance Method Summary collapse

Methods inherited from Abstract

#identifier, #initialize, setup!

Constructor Details

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

Instance Method Details

#retrieve!(identifier) ⇒ Object

Retrieve the file from its store path

Parameters

identifier (String)

the filename of the file

Returns

CarrierWave::SanitizedFile

a sanitized file



42
43
44
45
46
# File 'lib/carrierwave/storage/file.rb', line 42

def retrieve!(identifier)
  path = ::File.join(uploader.store_path(identifier))
  path = ::File.expand_path(path, uploader.public)
  CarrierWave::SanitizedFile.new(path)
end

#store!(file) ⇒ Object

Move the file to the uploader’s store path.

Parameters

file (CarrierWave::SanitizedFile)

the file to store

Returns

CarrierWave::SanitizedFile

a sanitized file



24
25
26
27
28
29
# File 'lib/carrierwave/storage/file.rb', line 24

def store!(file)
  path = ::File.join(uploader.store_path)
  path = ::File.expand_path(path, uploader.public)
  file.move_to(path, CarrierWave.config[:permissions])
  file
end