tencent_cloud_cos 0.1.0 → 0.2.0
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2f3bf5087921b3a854286401e528814a4cbf134
|
4
|
+
data.tar.gz: 84505e018b076600dfa79260210bb1bc790a95db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73ce8e59d17b7b4e6951e9da4842246cca5ba52b2a8e52d65047eb7a0c6d4c3670f6f721273b73a5e61991d89fd9ac901608af6e7151c4e5a32274591c79696c
|
7
|
+
data.tar.gz: acd5d39c0193c976f9a3b3772d3f458bf0d4210d9a5f8536380f067ba8728255b9366e267c562c75ed35f5a105eaf8aed7d6743e9f1f950c1a91bf13539f1a89
|
@@ -5,6 +5,7 @@ module TencentCloudCos
|
|
5
5
|
def put(file, filename)
|
6
6
|
config.method = 'put'
|
7
7
|
config.uri = filename
|
8
|
+
content_type = config.content_type
|
8
9
|
|
9
10
|
authorization = Authorization.new(config)
|
10
11
|
|
@@ -12,7 +13,8 @@ module TencentCloudCos
|
|
12
13
|
response = RestClient.put("#{config.host}#{config.uri}", file,
|
13
14
|
Authorization: authorization.auth_header,
|
14
15
|
host: config.host,
|
15
|
-
content_length: file.size
|
16
|
+
content_length: file.size,
|
17
|
+
content_type: content_type)
|
16
18
|
rescue RestClient::ExceptionWithResponse => e
|
17
19
|
return e.response
|
18
20
|
else
|
@@ -11,14 +11,14 @@ module TencentCloudCos
|
|
11
11
|
|
12
12
|
def sign
|
13
13
|
sign_key = OpenSSL::HMAC.hexdigest('sha1', secret_key, sign_time)
|
14
|
-
http_string = "#{method}\n#{uri}\n\
|
14
|
+
http_string = "#{method}\n#{uri}\n\ncontent-type=#{content_type}&host=#{host}\n"
|
15
15
|
sha1ed_http_string = Digest::SHA1.hexdigest http_string
|
16
16
|
string_to_sign = "sha1\n#{sign_time}\n#{sha1ed_http_string}\n"
|
17
17
|
signature = OpenSSL::HMAC.hexdigest('sha1', sign_key, string_to_sign)
|
18
18
|
end
|
19
19
|
|
20
20
|
def auth_header
|
21
|
-
auth = "q-sign-algorithm=sha1&q-ak=#{secret_id}&q-sign-time=#{sign_time}&q-key-time=#{sign_time}&q-header-list=host&q-url-param-list=&q-signature=#{sign}"
|
21
|
+
auth = "q-sign-algorithm=sha1&q-ak=#{secret_id}&q-sign-time=#{sign_time}&q-key-time=#{sign_time}&q-header-list=content-type;host&q-url-param-list=&q-signature=#{sign}"
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -47,6 +47,10 @@ module TencentCloudCos
|
|
47
47
|
"#{Time.now.to_i-60};#{Time.now.to_i + 3600}"
|
48
48
|
end
|
49
49
|
|
50
|
+
def content_type
|
51
|
+
URI::escape(@config.content_type, /\W/)
|
52
|
+
end
|
53
|
+
|
50
54
|
end
|
51
55
|
|
52
56
|
end
|
@@ -2,6 +2,10 @@ module TencentCloudCos
|
|
2
2
|
class Configuration
|
3
3
|
# uri: 上传文件名称
|
4
4
|
# method: 请求签名方法
|
5
|
-
attr_accessor :app_id, :secret_id, :secret_key, :bucket, :host, :uri, :method
|
5
|
+
attr_accessor :app_id, :secret_id, :secret_key, :bucket, :host, :uri, :method, :content_type
|
6
|
+
|
7
|
+
def content_type
|
8
|
+
@content_type || 'image/jpeg'
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tencent_cloud_cos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iamdbc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|