qiniu-rs 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiniu-rs (3.2.0)
4
+ qiniu-rs (3.2.1)
5
5
  json (~> 1.7)
6
6
  mime-types (~> 1.19)
7
7
  rest-client (~> 1.6)
data/docs/NEWS.md ADDED
@@ -0,0 +1,25 @@
1
+ ## CHANGE LOG
2
+
3
+ ### v3.2.1
4
+
5
+ allow images uploaded auto-orient.
6
+
7
+ 允许图片上传成功后自动旋转。
8
+
9
+ 参考:
10
+
11
+ 1. [[API] multipart/form-data 上传文件之 action 字段详解](http://docs.qiniutek.com/v3/api/io/#upload-action)
12
+ 2. [[SDK] Qiniu::RS.upload_file() 方法中的参数增加了 :rotate 选项](http://docs.qiniutek.com/v3/sdk/ruby/#upload-server-side)
13
+
14
+ ### v3.2.0
15
+
16
+ 2012-11-06
17
+
18
+ allow files uploaded auto callback some APIs (like imageInfo, exif, etc…), and add those APIs callback results as part of the custom data for POST biz-server.
19
+
20
+ 允许上传文件(图片)成功后执行回调指定的 API (比如 imageInfo, exif 接口等),并将指定API的回调结果一并 POST 发送给客户方的业务服务器。
21
+
22
+ 参考:
23
+
24
+ 1. [[API] 生成上传授权凭证 uploadToken 之 escape 参数详解](http://docs.qiniutek.com/v3/api/io/#escape-expression)
25
+ 2. [[SDK] Qiniu::RS.generate_upload_token() 方法中的参数增加了 :escape 选项](http://docs.qiniutek.com/v3/sdk/ruby/#generate-upload-token)
data/docs/README.md CHANGED
@@ -170,7 +170,8 @@ title: Ruby SDK 使用指南 | 七牛云存储
170
170
  :mime_type => file_mime_type,
171
171
  :note => some_notes,
172
172
  :callback_params => callback_params,
173
- :enable_crc32_check => false
173
+ :enable_crc32_check => false,
174
+ :rotate => auto_rotate
174
175
 
175
176
  **参数**
176
177
 
@@ -198,6 +199,9 @@ title: Ruby SDK 使用指南 | 七牛云存储
198
199
  :enable_crc32_check
199
200
  : 可选,Boolean 类型,是否启用文件上传 crc32 校验,缺省为 false 。
200
201
 
202
+ :rotate
203
+ : 可选,数字类型,上传图片时专用,可针对图片上传后进行旋转。该参数值为 0 :表示根据图像EXIF信息自动旋转;值为 1 : 右转90度;值为 2 :右转180度;值为 3 : 右转270度。
204
+
201
205
  **返回值**
202
206
 
203
207
  上传成功,返回如下一个 Hash:
data/lib/qiniu/rs.rb CHANGED
@@ -114,7 +114,8 @@ module Qiniu
114
114
  opts[:mime_type],
115
115
  opts[:note],
116
116
  opts[:customer],
117
- opts[:callback_params])
117
+ opts[:callback_params],
118
+ opts[:rotate])
118
119
  else
119
120
  code, data = IO.upload_with_token(opts[:uptoken],
120
121
  opts[:file],
@@ -123,7 +124,8 @@ module Qiniu
123
124
  opts[:mime_type],
124
125
  opts[:note],
125
126
  opts[:callback_params],
126
- opts[:enable_crc32_check])
127
+ opts[:enable_crc32_check],
128
+ opts[:rotate])
127
129
  end
128
130
  raise UploadFailedError.new(code, data) if code != StatusOK
129
131
  return data
data/lib/qiniu/rs/io.rb CHANGED
@@ -34,8 +34,8 @@ module Qiniu
34
34
  Auth.request url, ::IO.read(local_file), options
35
35
  end
36
36
 
37
- def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false)
38
- action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
37
+ def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false, rotate = nil)
38
+ action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check, rotate)
39
39
  callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
40
40
  callback_query_string = Utils.generate_query_string(callback_params)
41
41
  url = Config.settings[:up_host] + '/upload'
@@ -43,7 +43,7 @@ module Qiniu
43
43
  end
44
44
 
45
45
  private
46
- def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false)
46
+ def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false, rotate = nil)
47
47
  raise NoSuchFileError, local_file unless File.exist?(local_file)
48
48
  key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.nil?
49
49
  entry_uri = bucket + ':' + key
@@ -54,6 +54,7 @@ module Qiniu
54
54
  action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type)
55
55
  action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.nil?
56
56
  action_params += '/crc32/' + Utils.crc32checksum(local_file).to_s if enable_crc32_check
57
+ action_params += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0
57
58
  action_params
58
59
  end
59
60
 
data/lib/qiniu/rs/up.rb CHANGED
@@ -115,7 +115,8 @@ module Qiniu
115
115
  mime_type = nil,
116
116
  custom_meta = nil,
117
117
  customer = nil,
118
- callback_params = nil)
118
+ callback_params = nil,
119
+ rotate = nil)
119
120
  raise NoSuchFileError, local_file unless File.exist?(local_file)
120
121
  begin
121
122
  ifile = File.open(local_file, 'rb')
@@ -127,9 +128,9 @@ module Qiniu
127
128
  mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
128
129
  end
129
130
  if fsize > Config.settings[:block_size]
130
- code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params)
131
+ code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params, rotate)
131
132
  else
132
- code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true)
133
+ code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true, rotate)
133
134
  end
134
135
  [code, data]
135
136
  ensure
@@ -289,13 +290,14 @@ module Qiniu
289
290
  return [code, data]
290
291
  end
291
292
 
292
- def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil)
293
+ def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil)
293
294
  path = '/rs-mkfile/' + Utils.urlsafe_base64_encode(entry_uri) + "/fsize/#{fsize}"
294
295
  path += '/mimeType/' + Utils.urlsafe_base64_encode(mime_type) if !mime_type.nil? && !mime_type.empty?
295
296
  path += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) if !custom_meta.nil? && !custom_meta.empty?
296
297
  path += '/customer/' + customer if !customer.nil? && !customer.empty?
297
298
  callback_query_string = Utils.generate_query_string(callback_params) if !callback_params.nil? && !callback_params.empty?
298
299
  path += '/params/' + Utils.urlsafe_base64_encode(callback_query_string) if !callback_query_string.nil? && !callback_query_string.empty?
300
+ path += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0
299
301
  url = Config.settings[:up_host] + path
300
302
  body = ''
301
303
  checksums.each do |checksum|
@@ -304,7 +306,7 @@ module Qiniu
304
306
  _call_binary_with_token(uptoken, url, body)
305
307
  end
306
308
 
307
- def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil)
309
+ def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil)
308
310
  block_count = _block_count(fsize)
309
311
  progress_data = ProgressData.new(key)
310
312
  checksums = progress_data.get_checksums
@@ -322,7 +324,7 @@ module Qiniu
322
324
  code, data = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
323
325
  if Utils.is_response_ok?(code)
324
326
  entry_uri = bucket + ':' + key
325
- code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params)
327
+ code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params, rotate)
326
328
  end
327
329
  if Utils.is_response_ok?(code)
328
330
  Utils.debug "File #{fh.path} {size: #{fsize}} successfully uploaded."
@@ -5,7 +5,7 @@ module Qiniu
5
5
  module Version
6
6
  MAJOR = 3
7
7
  MINOR = 2
8
- PATCH = 0
8
+ PATCH = 1
9
9
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
10
10
  #
11
11
  # Example
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiniu-rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -138,6 +138,7 @@ files:
138
138
  - LICENSE
139
139
  - README.md
140
140
  - Rakefile
141
+ - docs/NEWS.md
141
142
  - docs/README.md
142
143
  - lib/qiniu-rs.rb
143
144
  - lib/qiniu/rs.rb
@@ -185,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
186
  version: '0'
186
187
  segments:
187
188
  - 0
188
- hash: -1772057481364600081
189
+ hash: -726479024348899519
189
190
  required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  none: false
191
192
  requirements:
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  version: '0'
195
196
  segments:
196
197
  - 0
197
- hash: -1772057481364600081
198
+ hash: -726479024348899519
198
199
  requirements: []
199
200
  rubyforge_project:
200
201
  rubygems_version: 1.8.24