carrierwave-qiniu 0.1.0 → 0.1.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: 681bc93e529a975aee0b4cbf79ca4c36b897303a
4
- data.tar.gz: 0f37e352a65ee828771e43e02a1562ff4a6ceb75
3
+ metadata.gz: 6389bb732e294a7f5bc3c107621c1d65d136440e
4
+ data.tar.gz: cc2efc74f9d673bc4b30779cd8dae0829e88c46c
5
5
  SHA512:
6
- metadata.gz: 0ef2ad3e0eb59fc0b9cf5bc6d354a631c495b61a9c67b6ef29a2b60af95c3097f25860010bcd452915ab5d7b86a4407189f12604801638f60e1b3e302dbcd001
7
- data.tar.gz: f699c01bb38d639be78d497dc5abdec9502810003178fc76c31c7d868a4a8228a0836a20b5fcf2312e256377e1ae370b7f59384ab63633eda24b832dc29be39b
6
+ metadata.gz: d9c59dc02dcfad40cdabb9c974a4e1b8acb4be84f593beefec6da7f4b4a78be94eef5ecfb5cad1f6df8b1311b1d6ce4e59abaea33c272eae8ad8aa4c688b6966
7
+ data.tar.gz: c0c20d6b8129d1aca7cfecef7161499028ecf4ee5be86015e53adae3d2c375666e258d3053fb3203fb5c83e5cb8277f894e5d18c8f818fbf6dab7969c66d33f1
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ group :test do
9
9
  gem 'sqlite3', '>=1.3.6'
10
10
  gem 'carrierwave', '>=0.6.2'
11
11
  gem 'mini_magick', '>=3.4'
12
- gem 'qiniu-rs', '~>3.4.2'
12
+ gem 'qiniu'
13
13
  gem 'rspec', '~> 2.11'
14
14
  gem 'mocha', '>=0.10.0'
15
15
  end
data/README.md CHANGED
@@ -29,12 +29,13 @@ You'll need to configure it in config/initializes/carrierwave.rb
29
29
  config.qiniu_secret_key = 'your qiniu secret_key'
30
30
  config.qiniu_bucket = "carrierwave-qiniu-example"
31
31
  config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
32
+ config.qiniu_bucket_private= true #default is false
32
33
  config.qiniu_block_size = 4*1024*1024
33
34
  config.qiniu_protocol = "http"
34
35
  end
35
36
  ```
36
37
 
37
- For more information on `qiniu_bucket_domain`, please read http://docs.qiniutek.com/v2/sdk/ruby/#publish
38
+ For more information on qiniu, please read http://developer.qiniu.com/docs/v6/
38
39
 
39
40
  And then in your uploader, set the storage to `:qiniu`:
40
41
 
@@ -54,6 +55,7 @@ class AvatarUploader < CarrierWave::Uploader::Base
54
55
  self.qiniu_bucket_domain = "avatars.files.example.com"
55
56
  self.qiniu_protocal = 'http'
56
57
  self.qiniu_can_overwrite = true
58
+ self.qiniu_bucket_private= true #default is false
57
59
 
58
60
  # See also:
59
61
  # https://github.com/qiniu/ruby-sdk/issues/48
@@ -82,4 +84,3 @@ You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-e
82
84
  ## Contributors
83
85
 
84
86
  See the [Contributors List](https://github.com/huobazi/carrierwave-qiniu/graphs/contributors).
85
-
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
 
19
19
 
20
20
  gem.add_dependency "carrierwave"
21
- gem.add_dependency "qiniu-rs",["~> 3.4.2"]
21
+ gem.add_dependency "qiniu",["~> 6.2.4"]
22
22
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
@@ -7,6 +7,7 @@ module CarrierWave
7
7
  included do
8
8
  add_config :qiniu_bucket_domain
9
9
  add_config :qiniu_bucket
10
+ add_config :qiniu_bucket_private
10
11
  add_config :qiniu_access_key
11
12
  add_config :qiniu_secret_key
12
13
  add_config :qiniu_block_size
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'carrierwave'
3
- require 'qiniu-rs'
3
+ require 'qiniu'
4
4
 
5
5
  module CarrierWave
6
6
  module Storage
@@ -10,10 +10,11 @@ module CarrierWave
10
10
  def initialize(options={})
11
11
  @qiniu_bucket_domain = options[:qiniu_bucket_domain]
12
12
  @qiniu_bucket = options[:qiniu_bucket]
13
+ @qiniu_bucket_private= options[:qiniu_bucket_private] || false
13
14
  @qiniu_access_key = options[:qiniu_access_key]
14
15
  @qiniu_secret_key = options[:qiniu_secret_key]
15
16
  @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
16
- @qiniu_protocol = options[:qiniu_protocol] || options[:qiniu_protocal] || "http"
17
+ @qiniu_protocol = options[:qiniu_protocol] || "http"
17
18
  @qiniu_async_ops = options[:qiniu_async_ops] || ''
18
19
  @qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
19
20
  init
@@ -22,66 +23,51 @@ module CarrierWave
22
23
  def store(file, key)
23
24
  qiniu_upload_scope = @qiniu_bucket
24
25
  qiniu_upload_scope = @qiniu_bucket + ':' + key if @qiniu_can_overwrite
25
- token_opts = {
26
- :scope => qiniu_upload_scope, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
27
- }
28
- token_opts.merge!(:async_options => @qiniu_async_ops) if @qiniu_async_ops.size > 0
29
26
 
30
- uptoken = ::Qiniu::RS.generate_upload_token(token_opts)
27
+ put_policy = ::Qiniu::Auth::PutPolicy.new(
28
+ @qiniu_bucket,
29
+ key,
30
+ 3600
31
+ )
31
32
 
32
- opts = {
33
- :uptoken => uptoken,
34
- :file => file.path,
35
- :key => key,
36
- :bucket => @qiniu_bucket,
37
- :mime_type => file.content_type,
38
- :enable_crc32_check => true
39
- }
40
-
41
- ::Qiniu::RS.upload_file opts
33
+ code, result, response_headers = ::Qiniu::Storage.upload_with_put_policy(
34
+ put_policy,
35
+ file.path,
36
+ key
37
+ )
42
38
 
43
39
  end
44
40
 
45
41
  def delete(key)
46
42
  begin
47
- ::Qiniu::RS.delete(@qiniu_bucket, key)
43
+ ::Qiniu::Storage.delete(@qiniu_bucket, key)
48
44
  rescue Exception => e
49
45
  nil
50
46
  end
51
47
  end
52
48
 
53
- def get_public_url(key)
54
- if @qiniu_bucket_domain and @qiniu_bucket_domain.size > 0
55
- "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{key}"
56
- else
57
- res = ::Qiniu::RS.get(@qiniu_bucket, key)
58
- if res
59
- res["url"]
60
- else
61
- nil
62
- end
63
- end
49
+ def download_url(path)
50
+ encode_path = URI.escape(path, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) #fix chinese file name, same as encodeURIComponent in js
51
+ primitive_url = "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{encode_path}"
52
+ @qiniu_bucket_private ? ::Qiniu::Auth.authorize_download_url(primitive_url) : primitive_url
64
53
  end
65
54
 
66
55
  private
56
+
67
57
  def init
68
58
  init_qiniu_rs_connection
69
- #setup_publish_bucket_and_domain
70
59
  end
71
60
 
72
61
  def init_qiniu_rs_connection
73
62
  return if @qiniu_rs_connection_inited
74
- ::Qiniu::RS.establish_connection! :access_key => @qiniu_access_key,
63
+
64
+ ::Qiniu.establish_connection! :access_key => @qiniu_access_key,
75
65
  :secret_key => @qiniu_secret_key,
76
66
  :block_size => @qiniu_block_size
77
67
 
78
68
  @qiniu_rs_connection_inited = true
79
69
  end
80
70
 
81
- def setup_publish_bucket_and_domain
82
- ::Qiniu::RS.publish(@qiniu_bucket_domain, @qiniu_bucket)
83
- end
84
-
85
71
  end
86
72
 
87
73
  class File
@@ -95,11 +81,7 @@ module CarrierWave
95
81
  end
96
82
 
97
83
  def url
98
- if @uploader.qiniu_bucket_domain and @uploader.qiniu_bucket_domain.size > 0
99
- "#{@uploader.qiniu_protocol || 'http'}://#{@uploader.qiniu_bucket_domain}/#{@path}"
100
- else
101
- qiniu_connection.get_public_url(@path)
102
- end
84
+ qiniu_connection.download_url(@path)
103
85
  end
104
86
 
105
87
  def store(file)
@@ -121,6 +103,7 @@ module CarrierWave
121
103
  :qiniu_secret_key => @uploader.qiniu_secret_key,
122
104
  :qiniu_bucket => @uploader.qiniu_bucket,
123
105
  :qiniu_bucket_domain => @uploader.qiniu_bucket_domain,
106
+ :qiniu_bucket_private=> @uploader.qiniu_bucket_private,
124
107
  :qiniu_block_size => @uploader.qiniu_block_size,
125
108
  :qiniu_protocol => @uploader.qiniu_protocol
126
109
  }
data/spec/spec_helper.rb CHANGED
@@ -25,10 +25,12 @@ ActiveRecord::Migration.verbose = false
25
25
  # 测试的时候需要修改这个地方
26
26
  ::CarrierWave.configure do |config|
27
27
  config.storage = :qiniu
28
- config.qiniu_access_key = 'your key'
29
- config.qiniu_secret_key = 'your key'
30
- config.qiniu_bucket = "spec-test"
31
- config.qiniu_bucket_domain = "spec-test.qiniudn.com"
28
+ config.qiniu_access_key = "xxx"
29
+ config.qiniu_secret_key = "xxx"
30
+
31
+ config.qiniu_bucket = "xxx"
32
+ config.qiniu_bucket_domain = "xxx"
33
+
32
34
  config.qiniu_block_size = 4*1024*1024
33
35
  config.qiniu_protocol = "http"
34
36
  end
data/spec/upload_spec.rb CHANGED
@@ -53,10 +53,6 @@ describe "CarrierWave Qiniu" do
53
53
 
54
54
  class Photo < ActiveRecord::Base
55
55
 
56
- %W(small little middle large).each do |style|
57
- define_method("#{style}_image_url".to_sym){ self.image.url.to_s + "/#{style}" }
58
- end
59
-
60
56
  mount_uploader :image, PhotoUploader
61
57
  end
62
58
 
@@ -77,18 +73,13 @@ describe "CarrierWave Qiniu" do
77
73
 
78
74
  photo.errors.count.should == 0
79
75
 
80
- open(photo.small_image_url).should_not == nil
81
- open(photo.little_image_url).should_not == nil
82
- open(photo.middle_image_url).should_not == nil
83
- open(photo.large_image_url).should_not == nil
84
-
85
76
  puts ""
86
77
  puts 'The image was uploaded to:'
87
78
  puts ""
88
- puts photo.small_image_url
89
- puts photo.little_image_url
90
- puts photo.middle_image_url
91
- puts photo.large_image_url
79
+
80
+ open(photo.image.url).should_not be_nil
81
+
82
+ puts photo.image.url
92
83
  end
93
84
  end
94
85
  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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: qiniu-rs
28
+ name: qiniu
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 3.4.2
33
+ version: 6.2.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 3.4.2
40
+ version: 6.2.4
41
41
  description: Qiniu Storage support for CarrierWave
42
42
  email:
43
43
  - huobazi@gmail.com