carrierwave-qiniu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  uploads/
19
+
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ group :test do
8
8
  gem 'sqlite3', '1.3.6'
9
9
  gem 'carrierwave', '0.6.2'
10
10
  gem 'mini_magick', '3.4'
11
- gem 'qiniu-rs', '2.3.3'
11
+ gem 'qiniu-rs', '3.0.3'
12
12
  gem 'rspec', '~> 2.11'
13
13
  gem 'mocha', '0.10.0'
14
14
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carrierwave::Qiniu
2
2
 
3
- storage [Carrierwave](https://github.com/jnicklas/carrierwave) attachments to http://qiniutek.com
3
+ This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
4
4
 
5
5
  example: https://github.com/huobazi/carrierwave-qiniu-example
6
6
 
@@ -32,7 +32,7 @@ You'll need to configure it in config/initializes/carrierwave.rb
32
32
  end
33
33
  ```
34
34
 
35
- for more information on `qiniu_bucket_domain`, please read http://docs.qiniutek.com/v2/sdk/ruby/#publish
35
+ For more information on `qiniu_bucket_domain`, please read http://docs.qiniutek.com/v2/sdk/ruby/#publish
36
36
 
37
37
  And then in your uploader, set the storage to `:qiniu`:
38
38
 
@@ -52,7 +52,7 @@ class AvatarUploader < CarrierWave::Uploader::Base
52
52
  self.qiniu_bucket_domain = "avatars.files.example.com"
53
53
  end
54
54
  ```
55
- You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example or see the spec test on http://xxxxxxxxxxx
55
+ 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
56
56
 
57
57
  ## Contributing
58
58
 
@@ -17,7 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
 
19
19
  gem.add_development_dependency "carrierwave"
20
- gem.add_development_dependency "qiniu-rs",["~> 2.3.3"]
21
- gem.add_development_dependency "rspec", ["~> 2.11"]
22
- gem.add_development_dependency "rake", ["~> 0.9"]
20
+ gem.add_development_dependency "qiniu-rs",["~> 3.0.3"]
23
21
  end
@@ -11,9 +11,6 @@ rescue LoadError
11
11
  raise "You dot't have the 'qiniu-rs' gem installed"
12
12
  end
13
13
 
14
- # Qiniu::RS.establish_connection! :access_key => 'fR8TmveK4Eon_9te76mGyLKyC7I0JFwqBr6tVFdp',
15
- # :secret_key => 'OhEs7BQAGMxoktRHvv1aNrxvosoM4C44cF6pmaMp'
16
-
17
14
  module CarrierWave
18
15
  module Storage
19
16
  class Qiniu < Abstract
@@ -28,25 +25,40 @@ module CarrierWave
28
25
 
29
26
  def store(file, key)
30
27
  init
31
- remote_upload_url = ::Qiniu::RS.put_auth
32
- opts = {
33
- :url => remote_upload_url,
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 opts
42
28
 
29
+ # API v2
30
+ # remote_upload_url = ::Qiniu::RS.put_auth
31
+ # opts = {
32
+ # :url => remote_upload_url,
33
+ # :file => file.path,
34
+ # :key => key,
35
+ # :bucket => @qiniu_bucket,
36
+ # :mime_type => file.content_type,
37
+ # :enable_crc32_check => true
38
+ # }
39
+
40
+ # ::Qiniu::RS.upload opts
41
+
42
+ token_opts = {
43
+ :scope => @qiniu_bucket, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
44
+ }
45
+ uptoken = ::Qiniu::RS.generate_upload_token(token_opts)
46
+ opts = {
47
+ :uptoken => uptoken,
48
+ :file => file.path,
49
+ :key => key,
50
+ :bucket => @qiniu_bucket,
51
+ :mime_type => file.content_type,
52
+ :enable_crc32_check => true
53
+ }
54
+
55
+ ::Qiniu::RS.upload_file opts
43
56
  end
44
57
 
45
58
  def delete(key)
46
59
  init
47
60
  begin
48
61
  Qiniu::RS.delete(@qiniu_bucket, key)
49
- true
50
62
  rescue Exception => e
51
63
  nil
52
64
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
data/spec/spec_helper.rb CHANGED
@@ -26,8 +26,8 @@ ActiveRecord::Migration.verbose = false
26
26
  # 测试的时候需要修改这个地方
27
27
  ::CarrierWave.configure do |config|
28
28
  config.storage = :qiniu
29
- config.qiniu_access_key = "your qiniu access_key"
30
- config.qiniu_secret_key = 'your qiniu secret_key'
29
+ config.qiniu_access_key = "rJ2cC5tKdpA74P-pJPnADWBEZQ39fFSRv3udaGMu"
30
+ config.qiniu_secret_key = 'Aeuc1BxLvrOIvp-kBQ4v96rCyDsSC-tYDkxlVBKv'
31
31
  config.qiniu_bucket = "spec-test"
32
32
  config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
33
33
  end
data/spec/upload_spec.rb CHANGED
@@ -37,7 +37,7 @@ describe "Upload" do
37
37
  end
38
38
 
39
39
  protected
40
- def secure_token(length=16)
40
+ def secure_token(length = 16)
41
41
  var = :"@#{mounted_as}_secure_token"
42
42
  model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
43
43
  end
@@ -59,7 +59,8 @@ describe "Upload" do
59
59
  context "Upload Image" do
60
60
  it "does upload image" do
61
61
  f = load_file("ruby-china.png")
62
- photo = Photo.create(:image => f)
62
+ photo = Photo.new(:image => f)
63
+ photo.save
63
64
  photo.errors.count.should == 0
64
65
  open(photo.image.url).should_not == nil
65
66
  open(photo.image.url).size.should == f.size
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-17 00:00:00.000000000 Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.3.3
37
+ version: 3.0.3
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,39 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.3.3
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '2.11'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.11'
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '0.9'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '0.9'
45
+ version: 3.0.3
78
46
  description: Qiniu Storage support for CarrierWave
79
47
  email:
80
48
  - huobazi@gmail.com