Class: Fog::Storage::Aliyun::Files
- Inherits:
-
Collection
- Object
- Collection
- Fog::Storage::Aliyun::Files
- Defined in:
- lib/fog/aliyun/models/storage/files.rb
Instance Method Summary collapse
- #all(_options = {}) ⇒ Object
- #each ⇒ Object
- #each_file_this_page ⇒ Object
- #get(key) ⇒ Object
- #get_http_url(key, expires, options = {}) ⇒ Object
- #get_https_url(key, expires, options = {}) ⇒ Object
- #get_url(key) ⇒ Object
- #head(key, _options = {}) ⇒ Object
- #new(attributes = {}) ⇒ Object
Instance Method Details
#all(_options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 16 def all( = {}) requires :directory if directory.key != '' && directory.key != '.' && !directory.key.nil? prefix = directory.key + '/' end files = service.list_objects(prefix: prefix)['Contents'] return if nil == files data = [] i = 0 files.each do |file| next unless file['Key'][0][-1] != '/' content_length = file['Size'][0].to_i key = file['Key'][0] lastModified = file['LastModified'][0] last_modified = if !lastModified.nil? && lastModified != '' Time.parse(lastModified).localtime end type = file['Type'][0] data[i] = { content_length: content_length, key: key, last_modified: last_modified, etag: file['ETag'][0], object_type: type } i += 1 end load(data) end |
#each ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 46 def each if !block_given? self else subset = dup.all subset.each_file_this_page { |f| yield f } while subset.length == (subset.limit || 10_000) subset = subset.all(marker: subset.last.key) subset.each_file_this_page { |f| yield f } end self end end |
#each_file_this_page ⇒ Object
45 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 45 alias each_file_this_page each |
#get(key) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 62 def get(key) requires :directory object = if directory.key == '' key else directory.key + '/' + key end begin data = service.get_object(object) rescue => error case error.response.body when /<Code>NoSuchKey<\/Code>/ nil else raise(error) end end contentLen = data[:headers]['Content-Length'].to_i if block_given? pagesNum = (contentLen + Excon::CHUNK_SIZE - 1) / Excon::CHUNK_SIZE for i in 1..pagesNum _start = (i - 1) * Excon::CHUNK_SIZE _end = i * Excon::CHUNK_SIZE - 1 range = "#{_start}-#{_end}" data = service.get_object(object, range) chunk = data[:body] yield(chunk) body = nil end else body = data[:body] end lastModified = data[:headers]['Last-Modified'] last_modified = if !lastModified.nil? && lastModified != '' Time.parse(lastModified).localtime end date = data[:headers]['Date'] date = (Time.parse(date).localtime if !date.nil? && date != '') file_data = { body: body, content_length: contentLen, key: key, last_modified: last_modified, content_type: data[:headers]['Content-Type'], etag: data[:headers]['ETag'], date: date, connection: data[:headers]['Connection'], accept_ranges: data[:headers]['Accept-Ranges'], server: data[:headers]['Server'], object_type: data[:headers]['x-oss-object-type'], content_disposition: data[:headers]['Content-Disposition'] } new(file_data) end |
#get_http_url(key, expires, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 133 def get_http_url(key, expires, = {}) requires :directory object = if directory.key == '' key else directory.key + '/' + key end service.get_object_http_url_public(object, expires, ) end |
#get_https_url(key, expires, options = {}) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 143 def get_https_url(key, expires, = {}) requires :directory object = if directory.key == '' key else directory.key + '/' + key end service.get_object_https_url_public(object, expires, ) end |
#get_url(key) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 123 def get_url(key) requires :directory object = if directory.key == '' key else directory.key + '/' + key end service.get_object_http_url_public(object, 3600) end |
#head(key, _options = {}) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 153 def head(key, = {}) requires :directory object = if directory.key == '' key else directory.key + '/' + key end data = service.head_object(object).data lastModified = data[:headers]['Last-Modified'] last_modified = if !lastModified.nil? && lastModified != '' Time.parse(lastModified).localtime end date = data[:headers]['Date'] date = (Time.parse(date).localtime if !date.nil? && date != '') file_data = { content_length: data[:headers]['Content-Length'].to_i, key: key, last_modified: last_modified, content_type: data[:headers]['Content-Type'], etag: data[:headers]['ETag'], date: date, connection: data[:headers]['Connection'], accept_ranges: data[:headers]['Accept-Ranges'], server: data[:headers]['Server'], object_type: data[:headers]['x-oss-object-type'] } new(file_data) rescue Fog::Storage::Aliyun::NotFound nil end |
#new(attributes = {}) ⇒ Object
186 187 188 189 |
# File 'lib/fog/aliyun/models/storage/files.rb', line 186 def new(attributes = {}) requires :directory super({ directory: directory }.merge!(attributes)) end |