lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.0.2 vs lib/paperclip/storage/qiniu.rb in paperclip-qiniu-0.0.3
- old
+ new
@@ -1,5 +1,7 @@
+require 'paperclip-qiniu/exceptions'
+
module Paperclip
module Storage
module Qiniu
def self.extended base
begin
@@ -72,17 +74,19 @@
::Qiniu::RS.establish_connection! @options[:qiniu_credentials]
inited = true
end
def upload(file, path)
- remote_upload_url = ::Qiniu::RS.put_auth
- opts = {:url => remote_upload_url,
+ upload_token = ::Qiniu::RS.generate_upload_token :scope => bucket
+ opts = {:uptoken => upload_token,
:file => file.path,
:key => path,
:bucket => bucket,
:mime_type => file.content_type,
:enable_crc32_check => true}
- ::Qiniu::RS.upload opts
+ unless ::Qiniu::RS.upload_file(opts)
+ raise Paperclip::Qiniu::UploadFailed
+ end
end
def bucket
@options[:bucket] || raise("bucket is nil")
end