Class: CarrierWave::Storage::File
- 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
Instance Method Summary collapse
-
#retrieve!(identifier) ⇒ Object
Retrieve the file from its store path.
-
#store!(file) ⇒ Object
Move the file to the uploader’s store path.
Methods inherited from Abstract
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
49 50 51 52 |
# File 'lib/carrierwave/storage/file.rb', line 49 def retrieve!(identifier) path = ::File.(uploader.store_path(identifier), uploader.root) CarrierWave::SanitizedFile.new(path) end |
#store!(file) ⇒ Object
Move the file to the uploader’s store path.
By default, store!() uses copy_to(), which operates by copying the file from the cache to the store, then deleting the file from the cache.
If move_to_store() is overriden to return true, then store!() uses move_to(), which simply moves the file from cache to store. Useful for large files.
Parameters
- file (CarrierWave::SanitizedFile)
-
the file to store
Returns
- CarrierWave::SanitizedFile
-
a sanitized file
29 30 31 32 33 34 35 36 |
# File 'lib/carrierwave/storage/file.rb', line 29 def store!(file) path = ::File.(uploader.store_path, uploader.root) if uploader.move_to_store file.move_to(path, uploader.) else file.copy_to(path, uploader.) end end |