carrierwave-qiniu 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +3 -2
- data/lib/carrierwave-qiniu/version.rb +2 -2
- data/lib/carrierwave/storage/qiniu.rb +14 -8
- data/spec/upload_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f480f9beeba0f2721902bff9075edcc12929ea8
|
4
|
+
data.tar.gz: 59992dcd0be07822fd1f0584f7cd793df52b36f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b237b492ab50e519611d23b1e70b6322c0c52587ec8a53e8be2bfaea9bcf814558b0694497129bc2db2deb2570ff71d818bc15f79f0042e4c05f34090c48a33f
|
7
|
+
data.tar.gz: 572cca06fbeb64d780f4c90e4c776ca94dad3e1ce67c371af9f2e7278fee244c76838080a02896940190c5b4a17bf4b4f733903fbbff610a39aa0281f403b7f1
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Carrierwave::Qiniu
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?0.2.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?0.2.3)](http://badge.fury.io/rb/carrierwave-qiniu)
|
4
4
|
|
5
5
|
This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
|
6
6
|
example: https://github.com/huobazi/carrierwave-qiniu-example
|
@@ -78,7 +78,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
|
|
78
78
|
|
79
79
|
end
|
80
80
|
```
|
81
|
-
You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example
|
81
|
+
You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example
|
82
|
+
|
82
83
|
or see the spec test on https://github.com/huobazi/carrierwave-qiniu/blob/master/spec/upload_spec.rb
|
83
84
|
|
84
85
|
## Contributing
|
@@ -42,12 +42,16 @@ module CarrierWave
|
|
42
42
|
put_policy.callback_body = @qiniu_callback_body if @qiniu_callback_body.present?
|
43
43
|
put_policy.persistent_notify_url = @qiniu_persistent_notify_url if @qiniu_persistent_notify_url.present?
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
resp_code, resp_body, resp_headers =
|
46
|
+
::Qiniu::Storage.upload_with_put_policy(
|
47
|
+
put_policy,
|
48
|
+
file.path,
|
49
|
+
key
|
50
|
+
)
|
51
|
+
|
52
|
+
if resp_code < 200 or resp_code >= 300
|
53
|
+
raise ::CarrierWave::UploadError, "Upload failed, status code: #{resp_code}, response: #{resp_body}"
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
57
|
#
|
@@ -58,7 +62,9 @@ module CarrierWave
|
|
58
62
|
#
|
59
63
|
def copy(origin, target)
|
60
64
|
code, result, _ = ::Qiniu::Storage.copy(@qiniu_bucket, origin, @qiniu_bucket, target)
|
61
|
-
|
65
|
+
if resp_code < 200 or resp_code >= 300
|
66
|
+
raise ::CarrierWave::IntegrityError, "Copy failed, status code: #{resp_code}, response: #{resp_body}"
|
67
|
+
end
|
62
68
|
end
|
63
69
|
|
64
70
|
def delete(key)
|
@@ -204,7 +210,7 @@ module CarrierWave
|
|
204
210
|
|
205
211
|
def store!(file)
|
206
212
|
f = ::CarrierWave::Storage::Qiniu::File.new(uploader, uploader.store_path(uploader.filename))
|
207
|
-
if file && file.copy_from_path
|
213
|
+
if file && file.respond_to?(:copy_from_path) and file.copy_from_path
|
208
214
|
f.copy_from file.copy_from_path
|
209
215
|
else
|
210
216
|
f.store(file)
|
data/spec/upload_spec.rb
CHANGED
@@ -72,6 +72,25 @@ require 'carrierwave/processing/mini_magick'
|
|
72
72
|
end
|
73
73
|
|
74
74
|
context "Upload Image" do
|
75
|
+
it "should save failed" do
|
76
|
+
class WrongUploader < PhotoUploader
|
77
|
+
self.qiniu_bucket = 'not_exists'
|
78
|
+
end
|
79
|
+
|
80
|
+
class Photo < ActiveRecord::Base
|
81
|
+
mount_uploader :image, WrongUploader
|
82
|
+
end
|
83
|
+
|
84
|
+
f = load_file("mm.jpg")
|
85
|
+
photo = Photo.new(:image => f)
|
86
|
+
photo.save
|
87
|
+
expect(photo).to_not be_valid
|
88
|
+
|
89
|
+
expect {
|
90
|
+
photo.save!
|
91
|
+
}.to raise_error
|
92
|
+
end
|
93
|
+
|
75
94
|
it "does upload image" do
|
76
95
|
f = load_file("mm.jpg")
|
77
96
|
photo = Photo.new(:image => f)
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marble Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|