aliyunoss 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aliyunoss/api.rb +13 -0
- data/lib/aliyunoss/bucket.rb +10 -0
- data/lib/aliyunoss/oss_request.rb +22 -2
- data/lib/aliyunoss/version.rb +1 -1
- data/spec/aliyunoss/bucket_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 433bc4b7e35cc8b1f84173e0962fbac93b4fae4b4e167b9b716e8d5f46418487
|
4
|
+
data.tar.gz: 60aa4bc582d36bf810196002be4c8152051f452de57b0ea975f6a05e6796da5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
#
|
data/lib/aliyunoss/bucket.rb
CHANGED
@@ -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
|
|
data/lib/aliyunoss/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|