Commit a6c4796e by LI Daobing

use qiniu-rs v3

parent 354d9341
...@@ -3,7 +3,7 @@ PATH ...@@ -3,7 +3,7 @@ PATH
specs: specs:
paperclip-qiniu (0.0.2) paperclip-qiniu (0.0.2)
paperclip paperclip
qiniu-rs qiniu-rs (~> 3.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
......
module Paperclip
module Qiniu
class Error < StandardError; end
class UploadFailed < Error; end
end
end
require 'paperclip-qiniu/exceptions'
module Paperclip module Paperclip
module Storage module Storage
module Qiniu module Qiniu
...@@ -74,14 +76,16 @@ module Paperclip ...@@ -74,14 +76,16 @@ module Paperclip
end end
def upload(file, path) def upload(file, path)
remote_upload_url = ::Qiniu::RS.put_auth upload_token = ::Qiniu::RS.generate_upload_token :scope => bucket
opts = {:url => remote_upload_url, opts = {:uptoken => upload_token,
:file => file.path, :file => file.path,
:key => path, :key => path,
:bucket => bucket, :bucket => bucket,
:mime_type => file.content_type, :mime_type => file.content_type,
:enable_crc32_check => true} :enable_crc32_check => true}
::Qiniu::RS.upload opts unless ::Qiniu::RS.upload_file(opts)
raise Paperclip::Qiniu::UploadFailed
end
end end
def bucket def bucket
......
...@@ -15,6 +15,6 @@ Gem::Specification.new do |gem| ...@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"] gem.require_paths = ["lib"]
gem.version = Paperclip::Qiniu::VERSION gem.version = Paperclip::Qiniu::VERSION
gem.add_dependency 'paperclip' gem.add_dependency 'paperclip'
gem.add_dependency 'qiniu-rs' gem.add_dependency 'qiniu-rs', '~> 3.0'
gem.add_development_dependency 'rspec' gem.add_development_dependency 'rspec'
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment