class CarrierWave::Storage::AliyunFile
Attributes
file[W]
filename[R]
identifier[R]
path[R]
uploader[R]
Public Class Methods
new(uploader, base, path)
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 12 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end
Public Instance Methods
content_type()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 56 def content_type headers[:content_type] end
content_type=(new_content_type)
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 60 def content_type=(new_content_type) headers[:content_type] = new_content_type end
copy_to(new_path)
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 86 def copy_to(new_path) bucket.copy_object(path, new_path) self.class.new(uploader, @base, new_path) end
delete()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 34 def delete bucket.delete(path) true rescue StandardError => e # If the file's not there, don't panic puts "carrierwave-aliyun delete file failed: #{e}" nil end
exists?()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 82 def exists? !!headers end
extension()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 91 def extension path_elements = path.split(".") path_elements.last if path_elements.size > 1 end
file()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 18 def file @file ||= bucket.get(path).try(:first) end
headers()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 75 def headers @headers ||= begin obj = bucket.head(path) obj.headers end end
original_filename()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 96 def original_filename return @original_filename if @original_filename if @file&.respond_to?(:original_filename) @file.original_filename elsif path ::File.basename(path) end end
read()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 28 def read object, body = bucket.get(path) @headers = object.headers body end
size()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 22 def size file.headers[:content_length].to_i rescue StandardError nil end
store(new_file, headers = {})
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 64 def store(new_file, headers = {}) if new_file.is_a?(self.class) new_file.copy_to(path) else fog_file = new_file.to_file bucket.put(path, fog_file, **headers) fog_file.close if fog_file && !fog_file.closed? end true end
url(opts = {})
click to toggle source
Generate file url params
:thumb - Aliyun OSS Image Processor option, etc: @100w_200h_95q
# File lib/carrierwave/storage/aliyun_file.rb, line 48 def url(opts = {}) if bucket.mode == :private bucket.private_get_url(path, **opts) else bucket.path_to_url(path, **opts) end end
Private Instance Methods
bucket()
click to toggle source
# File lib/carrierwave/storage/aliyun_file.rb, line 108 def bucket @bucket ||= CarrierWave::Aliyun::Bucket.new(uploader) end