Module: CarrierWave::Uploader::Store

Defined in:
lib/carrierwave/uploader/store.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#filenameObject

Override this in your Uploader to change the filename.

Be careful using record ids as filenames. If the filename is stored in the database the record id will be nil when the filename is set. Don’t use record ids unless you understand this limitation.

Do not use the version_name in the filename, as it will prevent versions from being loaded correctly.

Returns

String

a filename



77
78
79
# File 'lib/carrierwave/uploader/store.rb', line 77

def filename
  @filename
end

#retrieve_from_store!(identifier) ⇒ Object

Retrieves the file from the storage.

Parameters

identifier (String)

uniquely identifies the file to retrieve



136
137
138
139
140
# File 'lib/carrierwave/uploader/store.rb', line 136

def retrieve_from_store!(identifier)
  with_callbacks(:retrieve_from_store, identifier) do
    @file = storage.retrieve!(self, identifier)
  end
end

#store!(new_file = nil) ⇒ Object

Stores the file by passing it to this Uploader’s storage engine.

If new_file is omitted, a previously cached file will be stored.

Parameters

new_file (File, IOString, Tempfile)

any kind of file object



119
120
121
122
123
124
125
126
127
# File 'lib/carrierwave/uploader/store.rb', line 119

def store!(new_file=nil)
  cache!(new_file) if new_file
  if @file and @cache_id
    with_callbacks(:store, new_file) do
      @file = storage.store!(self, @file)
      @cache_id = nil
    end
  end
end

#store_dirObject

Override this in your Uploader to change the directory where the file backend stores files.

Other backends may or may not use this method, depending on their specific needs.

Returns

String

a directory



90
91
92
# File 'lib/carrierwave/uploader/store.rb', line 90

def store_dir
  CarrierWave.config[:store_dir]
end

#store_path(for_file = filename) ⇒ Object

Calculates the path where the file should be stored. If for_file is given, it will be used as the filename, otherwise CarrierWave::Uploader#filename is assumed.

Parameters

for_file (String)

name of the file <optional>

Returns

String

the store path



106
107
108
# File 'lib/carrierwave/uploader/store.rb', line 106

def store_path(for_file=filename)
  File.join(store_dir, full_filename(for_file))
end