Class: CarrierWave::Storage::QiniuFile
- Inherits:
-
Object
- Object
- CarrierWave::Storage::QiniuFile
- Defined in:
- lib/carrierwave/storage/qiniu_file.rb
Instance Attribute Summary collapse
-
#copy_from_path ⇒ Object
Returns the value of attribute copy_from_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uploader ⇒ Object
readonly
Returns the value of attribute uploader.
Instance Method Summary collapse
- #content_type ⇒ Object
- #copy_from(origin_path) ⇒ Boolean
- #copy_to(new_path) ⇒ Boolean
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(uploader, path) ⇒ QiniuFile
constructor
A new instance of QiniuFile.
- #move_to(new_path) ⇒ Boolean
- #original_filename ⇒ Object
-
#read ⇒ Object
Reads the contents of the file from Cloud Files.
- #size ⇒ Object
- #store(new_file) ⇒ Object
-
#url(options = {}) ⇒ Object
Return qiniu URl, maybe with style.
Constructor Details
#initialize(uploader, path) ⇒ QiniuFile
Returns a new instance of QiniuFile.
10 11 12 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 10 def initialize(uploader, path) @uploader, @path = uploader, path end |
Instance Attribute Details
#copy_from_path ⇒ Object
Returns the value of attribute copy_from_path.
8 9 10 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 8 def copy_from_path @copy_from_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 7 def path @path end |
#uploader ⇒ Object (readonly)
Returns the value of attribute uploader.
7 8 9 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 7 def uploader @uploader end |
Instance Method Details
#content_type ⇒ Object
91 92 93 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 91 def content_type file_info["mimeType"] || "application/octet-stream".freeze end |
#copy_from(origin_path) ⇒ Boolean
Note:
从指定路径复制文件
56 57 58 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 56 def copy_from(origin_path) qiniu_connection.copy(origin_path, @path) end |
#copy_to(new_path) ⇒ Boolean
Note:
复制文件到指定路径
65 66 67 68 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 65 def copy_to(new_path) qiniu_connection.copy(@path, new_path) self.class.new(@uploader, new_path) end |
#delete ⇒ Object
42 43 44 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 42 def delete qiniu_connection.delete @path end |
#exists? ⇒ Boolean
46 47 48 49 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 46 def exists? return true if qiniu_connection.stat(@path).present? false end |
#extension ⇒ Object
99 100 101 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 99 def extension @path.split(".").last end |
#filename ⇒ Object
103 104 105 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 103 def filename ::File.basename(@path) end |
#move_to(new_path) ⇒ Boolean
Note:
移动文件到指定路径
75 76 77 78 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 75 def move_to(new_path) qiniu_connection.move(@path, new_path) self.class.new(@uploader, new_path) end |
#original_filename ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 107 def original_filename return @original_filename if @original_filename if @file && @file.respond_to?(:original_filename) @file.original_filename elsif @path ::File.basename(@path) end end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
87 88 89 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 87 def read qiniu_connection.get(@path) if self.size > 0 end |
#size ⇒ Object
95 96 97 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 95 def size file_info["fsize"] || 0 end |
#store(new_file) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 29 def store(new_file) if new_file.is_a?(self.class) if new_file.respond_to?(:copy_from_path) && new_file.copy_from_path.present? new_file.copy_from new_file.copy_from_path else new_file.copy_to @path end else qiniu_connection.upload_file(new_file.path, @path) end true end |
#url(options = {}) ⇒ Object
Return qiniu URl, maybe with style
Parameters
- options (Hash)
-
optional options hash, 图片样式 { version: :thumb } 或者 { style: “imageView2/1/w/200” }
Returns
- String
24 25 26 27 |
# File 'lib/carrierwave/storage/qiniu_file.rb', line 24 def url( = {}) the_path = .present? ? path_with_style() : @path qiniu_connection.download_url(the_path) end |