class Bizside::FileUploader
storage.yml¶ ↑
storage.yml に fog エントリが定義されている場合、fog 参照先 のストレージの fog.container に保存します。
storage.yml が存在しない・又は fog エントリがない場合はローカルに保存します。
Public Instance Methods
cache!(new_file = sanitized_file)
click to toggle source
ファイル名の長さチェックが可能なように
Calls superclass method
# File lib/bizside/file_uploader.rb, line 44 def cache!(new_file = sanitized_file) begin super rescue Errno::ENAMETOOLONG => e if Bizside.config.file_uploader.ignore_long_filename_error? if self.model.respond_to?(:original_filename) self.model.original_filename = filename end else raise e end end end
downloaded_file()
click to toggle source
# File lib/bizside/file_uploader.rb, line 39 def downloaded_file Bizside.config.storage.fog? ? downloaded_file_from_fog(file.path) : file.path end
Private Instance Methods
download_file_from_fog(path)
click to toggle source
# File lib/bizside/file_uploader.rb, line 64 def download_file_from_fog(path) tmp_path = "/tmp/#{Bizside.config.add_on_name}-#{Bizside::StringUtils.current_time_string}-#{File.basename(path)}" raise "File download failed.(curl '#{file.url}' -o '#{tmp_path}')" unless system("curl '#{file.url}' -o '#{tmp_path}'") tmp_path end
download_file_from_fog_with_cache(path)
click to toggle source
# File lib/bizside/file_uploader.rb, line 70 def download_file_from_fog_with_cache(path) cache_path = "/" + path unless File.exist?(cache_path) FileUtils.mkdir_p(File.dirname(cache_path)) tmp_path = download_file_from_fog(path) raise "Failed to move file.(mv '#{tmp_path}' '#{cache_path}')" unless system("mv '#{tmp_path}' '#{cache_path}'") end cache_path end
downloaded_file_from_fog(path)
click to toggle source
# File lib/bizside/file_uploader.rb, line 60 def downloaded_file_from_fog(path) Bizside.config.storage.fog.cache? ? download_file_from_fog_with_cache(path) : download_file_from_fog(path) end