aliyunoss 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c22926d8762b8b4bf376899763a30ec4be2f719a4f304eb29012331d216c4a07
4
- data.tar.gz: b08fd3ba38eadc4c6813b074113e9e2ae4356e41236f19e961b4150c4993abf5
3
+ metadata.gz: 433bc4b7e35cc8b1f84173e0962fbac93b4fae4b4e167b9b716e8d5f46418487
4
+ data.tar.gz: 60aa4bc582d36bf810196002be4c8152051f452de57b0ea975f6a05e6796da5e
5
5
  SHA512:
6
- metadata.gz: 4f068b547a30385271f91d3f955d47a604f7ed622527d158d50cd659348243910fe0e2c7345ad481240a967846d90eea61d6cdf533537b6b4b3d0e8ec354780f
7
- data.tar.gz: e2cec40d40c0e8037755f1cadcdecb2c86652e376169901812feea4882eea0a50b15cba7542056255a3ec2dbb663f77c90b21339b277cd69e8eee07d61ecc47b
6
+ metadata.gz: 432a817f2035de139b8f529f258fa6b575929b0fc45cc840da9fbba19a416a901ad24c5bf82dc7a60fe4eee4ade25cfed8407e3bae6c053c29fc5590dc027fd3
7
+ data.tar.gz: bbba5fa52b383f6ef157cfcc7aa4de5d57e4bace25ba79bb30e3686ec328640f3f5df86cf7296230ceabe73eae05f0c3964a79b9aa8faab960a96559c1a9d1b8
data/lib/aliyunoss/api.rb CHANGED
@@ -208,6 +208,19 @@ HERE
208
208
  Aliyun::Oss::OssRequest.new(bucket, path).url_for_sharing(expires_in)
209
209
  end
210
210
 
211
+ #
212
+ # return headers for uploading object
213
+ # options
214
+ #
215
+ def headers_for_upload(bucket, path, filename: nil,
216
+ content_type:, content_length:, checksum:, custom_metadata: {})
217
+ Aliyun::Oss::OssRequest.new(bucket, path).headers_for_write(filename: filename,
218
+ content_type: content_type,
219
+ content_length: content_length,
220
+ checksum: checksum,
221
+ custom_metadata: custom_metadata)
222
+ end
223
+
211
224
  #
212
225
  # Post Object
213
226
  #
@@ -88,6 +88,16 @@ module Aliyun
88
88
  Aliyun::Oss::API.generate_share_url(self, path, expires_in)
89
89
  end
90
90
 
91
+ def direct_upload_headers(path, filename: nil,
92
+ content_type:, content_length:, checksum:, custom_metadata: {})
93
+ Aliyun::Oss::API.headers_for_upload(self, path,
94
+ filename: filename,
95
+ content_type: content_type,
96
+ content_length: content_length,
97
+ checksum: checksum,
98
+ custom_metadata: custom_metadata)
99
+ end
100
+
91
101
  #
92
102
  # Generate public url for path
93
103
  #
@@ -26,10 +26,10 @@ module Aliyun
26
26
  #
27
27
  def get_uri
28
28
  if @domain
29
- uri = URI("https://#{domain}/")
29
+ uri = URI("https://#{@domain}/")
30
30
  else
31
31
  if @bucket
32
- uri = URI("https://#{bucket.name}.#{bucket.location}.#{host}")
32
+ uri = URI("https://#{@bucket.name}.#{@bucket.location}.#{host}")
33
33
  else
34
34
  uri = URI("https://oss.#{host}")
35
35
  end
@@ -89,6 +89,25 @@ module Aliyun
89
89
  uri.to_s
90
90
  end
91
91
 
92
+ def headers_for_write(filename: nil, content_type:, content_length:,
93
+ checksum:, custom_metadata: {})
94
+ @headers = {
95
+ "Content-Type" => content_type,
96
+ "Content-MD5" => checksum,
97
+ "Date" => Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT'),
98
+ "Content-Length" => content_length
99
+ }
100
+
101
+ if filename != nil
102
+ @headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
103
+ end
104
+
105
+ request = Net::HTTP.send(:const_get, 'Put').new(get_uri)
106
+ @headers.each_pair {|k,v| request[k] = v}
107
+ @headers['Authorization'] = 'OSS ' + access_key_id + ':' + signature(request)
108
+ @headers
109
+ end
110
+
92
111
  #
93
112
  # Get http header value by attribute
94
113
  #
@@ -160,6 +179,7 @@ module Aliyun
160
179
  if @queries[k] then "#{k}=#{@queries[k]}" else "#{k}" end
161
180
  end
162
181
 
182
+
163
183
  "/#{@bucket.name}#{@path}?#{array.sort.join('&')}"
164
184
  end
165
185
 
@@ -1,5 +1,5 @@
1
1
  module Aliyun
2
2
  module Oss
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -41,6 +41,30 @@ describe Aliyun::Oss::Bucket do
41
41
  expect(data.length).to eq(File.open( File.join(__dir__, "png", "test-1.png")).size)
42
42
  end
43
43
 
44
+ it 'should generate direct upload headers' do
45
+ file = File.join(__dir__, 'png', 'test-1.png')
46
+ md5 = OpenSSL::Digest::MD5
47
+ checksum = Base64.encode64(md5.digest(IO.read(file))).strip
48
+ headers = @bucket.direct_upload_headers('/test-1.png',
49
+ filename: 'test-1.png',
50
+ content_type: 'image/png',
51
+ content_length: IO.read(file).bytesize,
52
+ checksum: checksum,
53
+ custom_metadata: {})
54
+
55
+ # Now let's upload using these headers
56
+ uri = URI("https://#{@bucket.name}.#{@bucket.location}.aliyuncs.com/test-1.png")
57
+ request = Net::HTTP::Put.new(uri)
58
+ headers.each_pair { |k,v| request[k] = v }
59
+ request.body = IO.read(file)
60
+
61
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
62
+ response = http.request(request)
63
+ expect(response.code.to_s).to eq('200')
64
+ end
65
+
66
+ end
67
+
44
68
  it 'should upload data to server in multipart way' do
45
69
  path = '/multi-part-test.dat'
46
70
  @bucket.multipart_upload_initiate(path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyunoss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yijiecc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-18 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri