lib/carrierwave/uploader/cache.rb in carrierwave-0.5.2 vs lib/carrierwave/uploader/cache.rb in carrierwave-0.5.3

- old
+ new

@@ -62,10 +62,23 @@ def cached? @cache_id end ## + # Caches the remotely stored file + # + # This is useful when about to process images. Most processing solutions + # require the file to be stored on the local filesystem. + # + def cache_stored_file! + sanitized = SanitizedFile.new :tempfile => StringIO.new(file.read), + :filename => File.basename(path), :content_type => file.content_type + + cache! sanitized + end + + ## # Returns a String which uniquely identifies the currently cached file for later retrieval # # === Returns # # [String] a cache name, in the format YYYYMMDD-HHMM-PID-RND/filename.txt @@ -85,12 +98,13 @@ # # [CarrierWave::FormNotMultipart] if the assigned parameter is a string # def cache!(new_file) new_file = CarrierWave::SanitizedFile.new(new_file) - raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form unless new_file.empty? + raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form + with_callbacks(:cache, new_file) do self.cache_id = CarrierWave.generate_cache_id unless cache_id @filename = new_file.filename self.original_filename = new_file.filename