diff --git a/Gemfile.lock b/Gemfile.lock
index afce319..badf1cd 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- qiniu-rs (3.2.0)
+ qiniu-rs (3.2.1)
json (~> 1.7)
mime-types (~> 1.19)
rest-client (~> 1.6)
diff --git a/docs/NEWS.md b/docs/NEWS.md
new file mode 100644
index 0000000..a2e60f2
--- /dev/null
+++ b/docs/NEWS.md
@@ -0,0 +1,25 @@
+## CHANGE LOG
+
+### v3.2.1
+
+allow images uploaded auto-orient.
+
+允许图片上传成功后自动旋转。
+
+参考:
+
+1. [[API] multipart/form-data 上传文件之 action 字段详解](http://docs.qiniutek.com/v3/api/io/#upload-action)
+2. [[SDK] Qiniu::RS.upload_file() 方法中的参数增加了 :rotate 选项](http://docs.qiniutek.com/v3/sdk/ruby/#upload-server-side)
+
+### v3.2.0
+
+2012-11-06
+
+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.
+
+允许上传文件(图片)成功后执行回调指定的 API (比如 imageInfo, exif 接口等),并将指定API的回调结果一并 POST 发送给客户方的业务服务器。
+
+参考:
+
+1. [[API] 生成上传授权凭证 uploadToken 之 escape 参数详解](http://docs.qiniutek.com/v3/api/io/#escape-expression)
+2. [[SDK] Qiniu::RS.generate_upload_token() 方法中的参数增加了 :escape 选项](http://docs.qiniutek.com/v3/sdk/ruby/#generate-upload-token)
\ No newline at end of file
diff --git a/docs/README.md b/docs/README.md
index 5ae1cc5..5421375 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -170,7 +170,8 @@ title: Ruby SDK 使用指南 | 七牛云存储
:mime_type => file_mime_type,
:note => some_notes,
:callback_params => callback_params,
- :enable_crc32_check => false
+ :enable_crc32_check => false,
+ :rotate => auto_rotate
**参数**
@@ -198,6 +199,9 @@ title: Ruby SDK 使用指南 | 七牛云存储
:enable_crc32_check
: 可选,Boolean 类型,是否启用文件上传 crc32 校验,缺省为 false 。
+:rotate
+: 可选,数字类型,上传图片时专用,可针对图片上传后进行旋转。该参数值为 0 :表示根据图像EXIF信息自动旋转;值为 1 : 右转90度;值为 2 :右转180度;值为 3 : 右转270度。
+
**返回值**
上传成功,返回如下一个 Hash:
diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb
index 0f70a8d..d714708 100755
--- a/lib/qiniu/rs.rb
+++ b/lib/qiniu/rs.rb
@@ -114,7 +114,8 @@ module Qiniu
opts[:mime_type],
opts[:note],
opts[:customer],
- opts[:callback_params])
+ opts[:callback_params],
+ opts[:rotate])
else
code, data = IO.upload_with_token(opts[:uptoken],
opts[:file],
@@ -123,7 +124,8 @@ module Qiniu
opts[:mime_type],
opts[:note],
opts[:callback_params],
- opts[:enable_crc32_check])
+ opts[:enable_crc32_check],
+ opts[:rotate])
end
raise UploadFailedError.new(code, data) if code != StatusOK
return data
diff --git a/lib/qiniu/rs/io.rb b/lib/qiniu/rs/io.rb
index 36d05cc..cccabe3 100755
--- a/lib/qiniu/rs/io.rb
+++ b/lib/qiniu/rs/io.rb
@@ -34,8 +34,8 @@ module Qiniu
Auth.request url, ::IO.read(local_file), options
end
- def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false)
- action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
+ 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)
+ action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check, rotate)
callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
callback_query_string = Utils.generate_query_string(callback_params)
url = Config.settings[:up_host] + '/upload'
@@ -43,7 +43,7 @@ module Qiniu
end
private
- def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false)
+ def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false, rotate = nil)
raise NoSuchFileError, local_file unless File.exist?(local_file)
key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.nil?
entry_uri = bucket + ':' + key
@@ -54,6 +54,7 @@ module Qiniu
action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type)
action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.nil?
action_params += '/crc32/' + Utils.crc32checksum(local_file).to_s if enable_crc32_check
+ action_params += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0
action_params
end
diff --git a/lib/qiniu/rs/up.rb b/lib/qiniu/rs/up.rb
index c54dbd4..5a02ea0 100755
--- a/lib/qiniu/rs/up.rb
+++ b/lib/qiniu/rs/up.rb
@@ -115,7 +115,8 @@ module Qiniu
mime_type = nil,
custom_meta = nil,
customer = nil,
- callback_params = nil)
+ callback_params = nil,
+ rotate = nil)
raise NoSuchFileError, local_file unless File.exist?(local_file)
begin
ifile = File.open(local_file, 'rb')
@@ -127,9 +128,9 @@ module Qiniu
mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
end
if fsize > Config.settings[:block_size]
- code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params)
+ code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params, rotate)
else
- code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true)
+ code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true, rotate)
end
[code, data]
ensure
@@ -289,13 +290,14 @@ module Qiniu
return [code, data]
end
- def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil)
+ def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil)
path = '/rs-mkfile/' + Utils.urlsafe_base64_encode(entry_uri) + "/fsize/#{fsize}"
path += '/mimeType/' + Utils.urlsafe_base64_encode(mime_type) if !mime_type.nil? && !mime_type.empty?
path += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) if !custom_meta.nil? && !custom_meta.empty?
path += '/customer/' + customer if !customer.nil? && !customer.empty?
callback_query_string = Utils.generate_query_string(callback_params) if !callback_params.nil? && !callback_params.empty?
path += '/params/' + Utils.urlsafe_base64_encode(callback_query_string) if !callback_query_string.nil? && !callback_query_string.empty?
+ path += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0
url = Config.settings[:up_host] + path
body = ''
checksums.each do |checksum|
@@ -304,7 +306,7 @@ module Qiniu
_call_binary_with_token(uptoken, url, body)
end
- def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil)
+ def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil)
block_count = _block_count(fsize)
progress_data = ProgressData.new(key)
checksums = progress_data.get_checksums
@@ -322,7 +324,7 @@ module Qiniu
code, data = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
if Utils.is_response_ok?(code)
entry_uri = bucket + ':' + key
- code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params)
+ code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params, rotate)
end
if Utils.is_response_ok?(code)
Utils.debug "File #{fh.path} {size: #{fsize}} successfully uploaded."
diff --git a/lib/qiniu/rs/version.rb b/lib/qiniu/rs/version.rb
index e2f7b70..39161dc 100755
--- a/lib/qiniu/rs/version.rb
+++ b/lib/qiniu/rs/version.rb
@@ -5,7 +5,7 @@ module Qiniu
module Version
MAJOR = 3
MINOR = 2
- PATCH = 0
+ PATCH = 1
# Returns a version string by joining MAJOR, MINOR, and PATCH with '.'
#
# Example