Commit e1bd195a by LI Daobing

it works for public host

but still have problem in generate path
parent ce137c46
...@@ -46,16 +46,23 @@ module Paperclip ...@@ -46,16 +46,23 @@ module Paperclip
def flush_deletes def flush_deletes
init init
for path in @queued_for_delete do for path in @queued_for_delete do
::Qiniu::RS.delete(bucket, path) ::Qiniu::RS.delete(bucket, fix_path(path))
end end
@queued_for_delete = [] @queued_for_delete = []
end end
def public_url(style = default_style) def public_url(style = default_style)
init init
res = ::Qiniu::RS.get(bucket, path(style)) if @options[:qiniu_host]
return res["url"] if res "#{dynamic_fog_host_for_style(style)}/#{fix_path(path(style))}"
nil else
res = ::Qiniu::RS.get(bucket, fix_path(path(style)))
if res
res["url"]
else
nil
end
end
end end
private private
...@@ -67,6 +74,7 @@ module Paperclip ...@@ -67,6 +74,7 @@ module Paperclip
end end
def upload(file, path) def upload(file, path)
path = fix_path(path)
remote_upload_url = ::Qiniu::RS.put_auth remote_upload_url = ::Qiniu::RS.put_auth
opts = {:url => remote_upload_url, opts = {:url => remote_upload_url,
:file => file.path, :file => file.path,
...@@ -75,12 +83,25 @@ module Paperclip ...@@ -75,12 +83,25 @@ module Paperclip
:mime_type => file.content_type, :mime_type => file.content_type,
:enable_crc32_check => true} :enable_crc32_check => true}
::Qiniu::RS.upload opts ::Qiniu::RS.upload opts
log "bucket=#{bucket}, key=#{path}, mime_type=#{file.content_type}"
log ::Qiniu::RS.get(bucket, path) log ::Qiniu::RS.get(bucket, path)
end end
def bucket def bucket
@options[:bucket] || raise("bucket is nil") @options[:bucket] || raise("bucket is nil")
end end
def dynamic_fog_host_for_style(style)
if @options[:qiniu_host].respond_to?(:call)
@options[:qiniu_host].call(self)
else
@options[:qiniu_host]
end
end
def fix_path(path)
path.gsub(/^\//, '')
end
end end
end end
end end
...@@ -3,8 +3,8 @@ require 'paperclip/storage/qiniu' ...@@ -3,8 +3,8 @@ require 'paperclip/storage/qiniu'
module Paperclip::Storage module Paperclip::Storage
describe Qiniu do describe Qiniu do
it "should works" do context 'exists?' do
1.should == 1 pending "it's hard to test paperclip plugin"
end end
end end
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