carrierwave-qiniu 0.0.6 → 0.0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7466c24b8bbad340cb158313bce99c1649c0ccb4
4
- data.tar.gz: 6d5152971794c5b28e3306ccfa01c4db5e56a46e
3
+ metadata.gz: 30a5d49adf6184ef9c7f0cc52ddc05ed74e04384
4
+ data.tar.gz: 904e00be456b48cb111fa57d4f283d7c10ec3fcc
5
5
  SHA512:
6
- metadata.gz: 88bd1de7f76d7c9bf7126a0918ed63deb2211b71498841da479584877274bb202183fe73668dc93bf013e713d2b943644067bc30fad56717abae10cbb9e667ec
7
- data.tar.gz: e9120ad9050bb2dd1bbfc163c1ff2e22838307b0e7ec9e575828a3b77463653df4e0377ea8bcf04399a23f190974944c371be8c2a4d313d20944d715755e10c2
6
+ metadata.gz: 4b6a5af9aa7f85b05a149363c8b1718c709b077b41b4278ba4ed19d75c36e9f10992ecdec8d651f3a89b4df71e4c0de44fb867c7b9d9f0fdaff05e43c9647471
7
+ data.tar.gz: 6668159f0f110a0b4e07b15f953025c5443b0a73f790a06d8a00543bca0ebdd7d234d8298395ea20a66a4a543be7c9cb3040f3d92e1c3877cba96c532a292d34
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ #source 'https://rubygems.org'
2
+ source 'http://ruby.taobao.org'
2
3
 
3
4
  # Specify your gem's dependencies in carrierwave-qiniu.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -52,6 +52,18 @@ class AvatarUploader < CarrierWave::Uploader::Base
52
52
 
53
53
  self.qiniu_bucket = "avatars"
54
54
  self.qiniu_bucket_domain = "avatars.files.example.com"
55
+
56
+ # See also:
57
+ # http://docs.qiniu.com/api/put.html#uploadToken
58
+ # http://docs.qiniutek.com/v3/api/io/#uploadToken-asyncOps
59
+ def qiniu_async_ops
60
+ commands = []
61
+ %W(small little middle large).each do |style|
62
+ commands << "http://#{self.qiniu_bucket_domain}/#{self.store_dir}/#{self.filename}/#{style}"
63
+ end
64
+ commands
65
+ end
66
+
55
67
  end
56
68
  ```
57
69
  You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example or see the spec test on https://github.com/huobazi/carrierwave-qiniu/blob/master/spec/upload_spec.rb
@@ -64,9 +76,7 @@ You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-e
64
76
  4. Push to the branch (`git push origin my-new-feature`)
65
77
  5. Create new Pull Request
66
78
 
79
+ ## Contributors
67
80
 
68
- ## CHANGELOG
69
-
70
- ### 0.0.1 (2012-08-17)
81
+ See the [Contributors List](https://github.com/huobazi/carrierwave-qiniu/graphs/contributors).
71
82
 
72
- * it works.
@@ -18,11 +18,12 @@ module CarrierWave
18
18
  class Connection
19
19
  def initialize(options={})
20
20
  @qiniu_bucket_domain = options[:qiniu_bucket_domain]
21
- @qiniu_bucket = options[:qiniu_bucket]
22
- @qiniu_access_key = options[:qiniu_access_key]
23
- @qiniu_secret_key = options[:qiniu_secret_key]
24
- @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
25
- @qiniu_protocal = options[:qiniu_protocal] || "http"
21
+ @qiniu_bucket = options[:qiniu_bucket]
22
+ @qiniu_access_key = options[:qiniu_access_key]
23
+ @qiniu_secret_key = options[:qiniu_secret_key]
24
+ @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
25
+ @qiniu_protocal = options[:qiniu_protocal] || "http"
26
+ @qiniu_async_ops = options[:qiniu_async_ops] || ''
26
27
  init
27
28
  end
28
29
 
@@ -30,21 +31,25 @@ module CarrierWave
30
31
  token_opts = {
31
32
  :scope => @qiniu_bucket, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
32
33
  }
34
+ token_opts.merge!(:async_options => @qiniu_async_ops) if @qiniu_async_ops.size > 0
35
+
33
36
  uptoken = ::Qiniu::RS.generate_upload_token(token_opts)
37
+
34
38
  opts = {
35
- :uptoken => uptoken,
36
- :file => file.path,
37
- :key => key,
38
- :bucket => @qiniu_bucket,
39
- :mime_type => file.content_type,
40
- :enable_crc32_check => true
41
- }
39
+ :uptoken => uptoken,
40
+ :file => file.path,
41
+ :key => key,
42
+ :bucket => @qiniu_bucket,
43
+ :mime_type => file.content_type,
44
+ :enable_crc32_check => true
45
+ }
42
46
 
43
47
  ::Qiniu::RS.upload_file opts
48
+
44
49
  end
45
50
 
46
51
  def delete(key)
47
- begin
52
+ begin
48
53
  ::Qiniu::RS.delete(@qiniu_bucket, key)
49
54
  rescue Exception => e
50
55
  nil
@@ -73,8 +78,8 @@ module CarrierWave
73
78
  def init_qiniu_rs_connection
74
79
  return if @qiniu_rs_connection_inited
75
80
  ::Qiniu::RS.establish_connection! :access_key => @qiniu_access_key,
76
- :secret_key => @qiniu_secret_key,
77
- :block_size => @qiniu_block_size
81
+ :secret_key => @qiniu_secret_key,
82
+ :block_size => @qiniu_block_size
78
83
 
79
84
  @qiniu_rs_connection_inited = true
80
85
  end
@@ -118,13 +123,22 @@ module CarrierWave
118
123
  @qiniu_connection
119
124
  else
120
125
  config = {
121
- :qiniu_access_key => @uploader.qiniu_access_key,
122
- :qiniu_secret_key => @uploader.qiniu_secret_key,
123
- :qiniu_bucket => @uploader.qiniu_bucket,
124
- :qiniu_bucket_domain => @uploader.qiniu_bucket_domain,
125
- :qiniu_block_size => @uploader.qiniu_block_size,
126
- :qiniu_protocal => @uploader.qiniu_protocal
126
+ :qiniu_access_key => @uploader.qiniu_access_key,
127
+ :qiniu_secret_key => @uploader.qiniu_secret_key,
128
+ :qiniu_bucket => @uploader.qiniu_bucket,
129
+ :qiniu_bucket_domain => @uploader.qiniu_bucket_domain,
130
+ :qiniu_block_size => @uploader.qiniu_block_size,
131
+ :qiniu_protocal => @uploader.qiniu_protocal
127
132
  }
133
+
134
+ if @uploader.respond_to?(:qiniu_async_ops) and !@uploader.qiniu_async_ops.nil? and @uploader.qiniu_async_ops.size > 0
135
+ if @uploader.qiniu_async_ops.is_a?(Array)
136
+ config.merge!(:qiniu_async_ops => @uploader.qiniu_async_ops.join(';'))
137
+ else
138
+ config.merge!(:qiniu_async_ops => @uploader.qiniu_async_ops)
139
+ end
140
+ end
141
+
128
142
  @qiniu_connection ||= Connection.new config
129
143
  end
130
144
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7.1"
5
5
  end
6
6
  end
data/spec/mm.jpg ADDED
Binary file
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,6 @@ require "rails"
6
6
  require "active_record"
7
7
  require "carrierwave"
8
8
  require "carrierwave/orm/activerecord"
9
- require "carrierwave/processing/mini_magick"
10
9
 
11
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
12
11
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","lib"))
@@ -26,12 +25,14 @@ ActiveRecord::Migration.verbose = false
26
25
  # 测试的时候需要修改这个地方
27
26
  ::CarrierWave.configure do |config|
28
27
  config.storage = :qiniu
29
- config.qiniu_access_key = "rJ2cC5tKdpA74P-pJPnADWBEZQ39fFSRv3udaGMu"
30
- config.qiniu_secret_key = 'Aeuc1BxLvrOIvp-kBQ4v96rCyDsSC-tYDkxlVBKv'
28
+ config.qiniu_access_key = 'CsYEw1QBZAIPqp4q6wxb3s5Y6AIIuMIgGLW1MEIH'
29
+ config.qiniu_secret_key = 'avkqArZO-O3O736X_hf9-eL5CE2o-nlznwLq4Bzc'
31
30
  config.qiniu_bucket = "spec-test"
32
- config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
31
+ config.qiniu_bucket_domain = "spec-test.qiniudn.com"
32
+ config.qiniu_block_size = 4*1024*1024
33
+ config.qiniu_protocal = "http"
33
34
  end
34
35
 
35
36
  def load_file(fname)
36
37
  File.open([Rails.root,fname].join("/"))
37
- end
38
+ end
data/spec/upload_spec.rb CHANGED
@@ -6,7 +6,7 @@ require "open-uri"
6
6
 
7
7
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
8
8
 
9
- describe "Upload" do
9
+ describe "CarrierWave Qiniu" do
10
10
  def setup_db
11
11
  ActiveRecord::Schema.define(:version => 1) do
12
12
  create_table :photos do |t|
@@ -14,28 +14,35 @@ describe "Upload" do
14
14
  end
15
15
  end
16
16
  end
17
-
17
+
18
18
  def drop_db
19
19
  ActiveRecord::Base.connection.tables.each do |table|
20
20
  ActiveRecord::Base.connection.drop_table(table)
21
21
  end
22
22
  end
23
-
23
+
24
24
  class PhotoUploader < CarrierWave::Uploader::Base
25
- include CarrierWave::MiniMagick
26
25
 
27
- version :small do
28
- process :resize_to_fill => [100, 100]
29
- end
30
-
31
26
  def store_dir
32
- "photos"
27
+ "carrierwave-qiniu-spec"
33
28
  end
34
29
 
35
30
  def filename
36
31
  "images/#{secure_token(10)}.#{file.extension}" if original_filename.present?
37
32
  end
38
33
 
34
+ # See
35
+ # http://docs.qiniu.com/api/put.html#uploadToken
36
+ # http://docs.qiniutek.com/v3/api/io/#uploadToken-asyncOps
37
+ def qiniu_async_ops
38
+ commands = []
39
+ %W(small little middle large).each do |style|
40
+ commands << "http://#{self.qiniu_bucket_domain}/#{self.store_dir}/#{self.filename}/#{style}"
41
+ end
42
+ commands
43
+ end
44
+
45
+
39
46
  protected
40
47
  def secure_token(length = 16)
41
48
  var = :"@#{mounted_as}_secure_token"
@@ -44,32 +51,43 @@ describe "Upload" do
44
51
  end
45
52
 
46
53
  class Photo < ActiveRecord::Base
54
+
55
+ %W(small little middle large).each do |style|
56
+ define_method("#{style}_image_url".to_sym){ self.image.url.to_s + "/#{style}" }
57
+ end
58
+
47
59
  mount_uploader :image, PhotoUploader
48
60
  end
49
-
50
-
61
+
62
+
51
63
  before :all do
52
64
  setup_db
53
65
  end
54
-
66
+
55
67
  after :all do
56
68
  drop_db
57
69
  end
58
-
70
+
59
71
  context "Upload Image" do
60
72
  it "does upload image" do
61
- f = load_file("ruby-china.png")
73
+ f = load_file("mm.jpg")
62
74
  photo = Photo.new(:image => f)
63
75
  photo.save
76
+
64
77
  photo.errors.count.should == 0
65
- open(photo.image.url).should_not == nil
66
- open(photo.image.url).size.should == f.size
67
- open(photo.image.small.url).should_not == nil
78
+
79
+ open(photo.small_image_url).should_not == nil
80
+ open(photo.little_image_url).should_not == nil
81
+ open(photo.middle_image_url).should_not == nil
82
+ open(photo.large_image_url).should_not == nil
83
+
68
84
  puts ""
69
85
  puts 'The image was uploaded to:'
70
86
  puts ""
71
- puts photo.image.url
72
- puts photo.image.small.url
87
+ puts photo.small_image_url
88
+ puts photo.little_image_url
89
+ puts photo.middle_image_url
90
+ puts photo.large_image_url
73
91
  end
74
92
  end
75
- end
93
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - huobazi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-25 00:00:00.000000000 Z
11
+ date: 2013-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -55,7 +55,7 @@ files:
55
55
  - lib/carrierwave-qiniu/version.rb
56
56
  - lib/carrierwave/qiniu/configuration.rb
57
57
  - lib/carrierwave/storage/qiniu.rb
58
- - spec/ruby-china.png
58
+ - spec/mm.jpg
59
59
  - spec/spec_helper.rb
60
60
  - spec/upload_spec.rb
61
61
  homepage: https://github.com/huobazi/carrierwave-qiniu
@@ -77,11 +77,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.0.2
80
+ rubygems_version: 2.0.3
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Qiniu Storage support for CarrierWave
84
84
  test_files:
85
- - spec/ruby-china.png
85
+ - spec/mm.jpg
86
86
  - spec/spec_helper.rb
87
87
  - spec/upload_spec.rb
data/spec/ruby-china.png DELETED
Binary file