Class: Lhj::OSS::Helper
- Inherits:
-
Object
- Object
- Lhj::OSS::Helper
- Defined in:
- lib/lhj/helper/oss_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #acl=(acl) ⇒ Object
- #alc ⇒ Object
- #batch_delete(keys) ⇒ Object
- #cors ⇒ Object
- #delete(key) ⇒ Object
- #down_load(key, file, &block) ⇒ Object
- #get_bucket(name) ⇒ Object
-
#initialize ⇒ Helper
constructor
A new instance of Helper.
- #lifecycle ⇒ Object
-
#list(opts = {}) ⇒ Object
@bucket.list_objects({ prefix: ‘tool/config’ }) 前缀过滤 @bucket.list_objects({ marker: ‘code/README.md’ }) 当前key之前后 @bucket.list_objects({ delimiter: ‘/’ }).filter { |o| o.is_a?(String) } 分割符, 获取所有目录结构.
-
#list_bucket ⇒ Object
bucketbucket.name #bucketbucket.location.
- #logging ⇒ Object
- #object_url(key) ⇒ Object
- #put_object(key, opts = {}, &block) ⇒ Object
- #referer ⇒ Object
- #set_object_acl(key, acl) ⇒ Object
- #upload(key, file) ⇒ Object
- #upload_file_callback(key, file, callback_param = {}) ⇒ Object
- #url_path ⇒ Object
- #website ⇒ Object
Constructor Details
#initialize ⇒ Helper
Returns a new instance of Helper.
7 8 9 10 11 12 |
# File 'lib/lhj/helper/oss_helper.rb', line 7 def initialize @client = Aliyun::OSS::Client.new(endpoint: Lhj::OSSConfig.oss_endpoint, access_key_id: Lhj::OSSConfig.oss_access_key_id, access_key_secret: Lhj::OSSConfig.oss_access_key_secret) @bucket = @client.get_bucket(Lhj::OSSConfig.oss_bucket) end |
Class Method Details
.instance ⇒ Object
103 104 105 |
# File 'lib/lhj/helper/oss_helper.rb', line 103 def self.instance @instance ||= new end |
Instance Method Details
#acl=(acl) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lhj/helper/oss_helper.rb', line 64 def acl=(acl) case acl when :public_read_write @bucket.acl = (Aliyun::OSS::ACL::PUBLIC_READ_WRITE) when :public_read @bucket.acl = (Aliyun::OSS::ACL::PUBLIC_READ) when :private @bucket.acl = (Aliyun::OSS::ACL::PRIVATE) end end |
#alc ⇒ Object
79 80 81 |
# File 'lib/lhj/helper/oss_helper.rb', line 79 def alc @bucket.acl end |
#batch_delete(keys) ⇒ Object
60 61 62 |
# File 'lib/lhj/helper/oss_helper.rb', line 60 def batch_delete(keys) @bucket.batch_delete_objects(keys) end |
#cors ⇒ Object
91 92 93 |
# File 'lib/lhj/helper/oss_helper.rb', line 91 def cors @bucket.cors end |
#delete(key) ⇒ Object
56 57 58 |
# File 'lib/lhj/helper/oss_helper.rb', line 56 def delete(key) @bucket.delete_object(key) end |
#down_load(key, file, &block) ⇒ Object
36 37 38 |
# File 'lib/lhj/helper/oss_helper.rb', line 36 def down_load(key, file, &block) @bucket.get_object(key, :file => file, &block) end |
#get_bucket(name) ⇒ Object
14 15 16 |
# File 'lib/lhj/helper/oss_helper.rb', line 14 def get_bucket(name) @bucket = @client.get_bucket(name) end |
#lifecycle ⇒ Object
87 88 89 |
# File 'lib/lhj/helper/oss_helper.rb', line 87 def lifecycle @bucket.lifecycle end |
#list(opts = {}) ⇒ Object
@bucket.list_objects({ prefix: ‘tool/config’ }) 前缀过滤@bucket.list_objects({ marker: ‘code/README.md’ }) 当前key之前后@bucket.list_objects({ delimiter: ‘/’ }).filter { |o| o.is_a?(String) } 分割符, 获取所有目录结构
47 48 49 |
# File 'lib/lhj/helper/oss_helper.rb', line 47 def list(opts = {}) @bucket.list_objects(opts) end |
#list_bucket ⇒ Object
Lhj::OSS::Helper.bucketbucket.name #Lhj::OSS::Helper.bucketbucket.location
52 53 54 |
# File 'lib/lhj/helper/oss_helper.rb', line 52 def list_bucket @client.list_buckets end |
#logging ⇒ Object
83 84 85 |
# File 'lib/lhj/helper/oss_helper.rb', line 83 def logging @bucket.logging end |
#object_url(key) ⇒ Object
40 41 42 |
# File 'lib/lhj/helper/oss_helper.rb', line 40 def object_url(key) @bucket.object_url(key, false) end |
#put_object(key, opts = {}, &block) ⇒ Object
31 32 33 34 |
# File 'lib/lhj/helper/oss_helper.rb', line 31 def put_object(key, opts = {}, &block) args = opts.dup @bucket.put_object(key, args, &block) end |
#referer ⇒ Object
99 100 101 |
# File 'lib/lhj/helper/oss_helper.rb', line 99 def referer @bucket.referer end |
#set_object_acl(key, acl) ⇒ Object
75 76 77 |
# File 'lib/lhj/helper/oss_helper.rb', line 75 def set_object_acl(key, acl) @bucket.set_object_acl(key, acl) end |
#upload(key, file) ⇒ Object
22 23 24 |
# File 'lib/lhj/helper/oss_helper.rb', line 22 def upload(key, file) @bucket.put_object(key, :file => file) end |
#upload_file_callback(key, file, callback_param = {}) ⇒ Object
26 27 28 29 |
# File 'lib/lhj/helper/oss_helper.rb', line 26 def upload_file_callback(key, file, callback_param = {}) callback = Aliyun::OSS::Callback.new(callback_param) @bucket.put_object(key, { file: file, callback: callback }) end |
#url_path ⇒ Object
18 19 20 |
# File 'lib/lhj/helper/oss_helper.rb', line 18 def url_path Lhj::OSSConfig.oss_domain || "http://#{Lhj::OSSConfig.oss_bucket}.#{Lhj::OSSConfig.oss_endpoint}" end |
#website ⇒ Object
95 96 97 |
# File 'lib/lhj/helper/oss_helper.rb', line 95 def website @bucket.website end |