carrierwave-upyun 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +53 -0
- data/carrierwave-upyun.gemspec +1 -1
- data/lib/carrierwave/storage/upyun.rb +15 -15
- data/spec/foo.jpg +0 -0
- data/spec/upload_spec.rb +8 -6
- metadata +31 -11
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -33,3 +33,56 @@ class AvatarUploader < CarrierWave::Uploader::Base
|
|
33
33
|
end
|
34
34
|
```
|
35
35
|
|
36
|
+
You can override configuration item in individual uploader like this:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
40
|
+
storage :upyun
|
41
|
+
|
42
|
+
self.upyun_bucket = "avatars"
|
43
|
+
self.upyun_bucket_domain = "avatars.files.example.com"
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Configuration for use UpYun "Image Space"
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# The defined image name versions to limit use
|
51
|
+
IMAGE_UPLOADER_ALLOW_IMAGE_VERSION_NAMES = %(320 640 800)
|
52
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
53
|
+
def store_dir
|
54
|
+
"#{model.class.to_s.underscore}/#{mounted_as}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def default_url
|
58
|
+
# You can use FTP to upload a default image
|
59
|
+
"#{Setting.upload_url}/blank.png#{version_name}"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Override url method to implement with "Image Space"
|
63
|
+
def url(version_name = "")
|
64
|
+
@url ||= super({})
|
65
|
+
version_name = version_name.to_s
|
66
|
+
return @url if version_name.blank?
|
67
|
+
if not version_name.in?(IMAGE_UPLOADER_ALLOW_IMAGE_VERSION_NAMES)
|
68
|
+
# To protected version name using, when it not defined, this will be give an error message in development environment
|
69
|
+
raise "ImageUploader version_name:#{version_name} not allow."
|
70
|
+
end
|
71
|
+
[@url,version_name].join("!") # thumb split with "!"
|
72
|
+
end
|
73
|
+
|
74
|
+
def extension_white_list
|
75
|
+
%w(jpg jpeg gif png)
|
76
|
+
end
|
77
|
+
|
78
|
+
def filename
|
79
|
+
if super.present?
|
80
|
+
model.uploader_secure_token ||= SecureRandom.uuid.gsub("-","")
|
81
|
+
Rails.logger.debug("(BaseUploader.filename) #{model.uploader_secure_token}")
|
82
|
+
"#{model.uploader_secure_token}.#{file.extension.downcase}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
To see more details about use UpYun: [http://huacnlee.com/blog/rails-app-image-store-with-carrierwave-upyun/](http://huacnlee.com/blog/rails-app-image-store-with-carrierwave-upyun/)
|
data/carrierwave-upyun.gemspec
CHANGED
@@ -22,7 +22,7 @@ module CarrierWave
|
|
22
22
|
#
|
23
23
|
#
|
24
24
|
class UpYun < Abstract
|
25
|
-
|
25
|
+
|
26
26
|
class Connection
|
27
27
|
def initialize(options={})
|
28
28
|
@upyun_username = options[:upyun_username]
|
@@ -30,27 +30,27 @@ module CarrierWave
|
|
30
30
|
@upyun_bucket = options[:upyun_bucket]
|
31
31
|
@connection_options = options[:connection_options] || {}
|
32
32
|
@host = options[:api_host] || 'http://v0.api.upyun.com'
|
33
|
-
|
34
|
-
:user => @upyun_username,
|
33
|
+
@@http ||= RestClient::Resource.new("#{@host}/#{@upyun_bucket}",
|
34
|
+
:user => @upyun_username,
|
35
35
|
:password => @upyun_password)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def put(path, payload, headers = {})
|
39
|
-
|
39
|
+
@@http["#{escaped(path)}"].put(payload, headers)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def get(path, headers = {})
|
43
|
-
|
43
|
+
@@http["#{escaped(path)}"].get(headers)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def delete(path, headers = {})
|
47
|
-
|
47
|
+
@@http["#{escaped(path)}"].delete(headers)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def post(path, payload, headers = {})
|
51
|
-
|
51
|
+
@@http["#{escaped(path)}"].post(payload, headers)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def escaped(path)
|
55
55
|
CGI.escape(path)
|
56
56
|
end
|
@@ -116,7 +116,7 @@ module CarrierWave
|
|
116
116
|
nil
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def content_type
|
121
121
|
headers[:content_type]
|
122
122
|
end
|
@@ -155,8 +155,8 @@ module CarrierWave
|
|
155
155
|
if @uy_connection
|
156
156
|
@uy_connection
|
157
157
|
else
|
158
|
-
config = {:upyun_username => @uploader.upyun_username,
|
159
|
-
:upyun_password => @uploader.upyun_password,
|
158
|
+
config = {:upyun_username => @uploader.upyun_username,
|
159
|
+
:upyun_password => @uploader.upyun_password,
|
160
160
|
:upyun_bucket => @uploader.upyun_bucket
|
161
161
|
}
|
162
162
|
config[:api_host] = @uploader.upyun_api_host if @uploader.respond_to?(:upyun_api_host)
|
data/spec/foo.jpg
CHANGED
Binary file
|
data/spec/upload_spec.rb
CHANGED
@@ -46,11 +46,13 @@ describe "Upload" do
|
|
46
46
|
context "Upload Image" do
|
47
47
|
it "does upload image" do
|
48
48
|
f = load_file("foo.jpg")
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
open(photo.image.
|
49
|
+
puts Benchmark.measure {
|
50
|
+
@photo = Photo.create(:image => f)
|
51
|
+
}
|
52
|
+
@photo.errors.count.should == 0
|
53
|
+
open(@photo.image.url).should_not == nil
|
54
|
+
open(@photo.image.url).size.should == f.size
|
55
|
+
open(@photo.image.small.url).should_not == nil
|
54
56
|
end
|
55
57
|
end
|
56
|
-
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-upyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.5.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.7
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rest-client
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 1.6.7
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.7
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '2.6'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rake
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0.9'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.9'
|
58
78
|
description: UpYun Storage support for CarrierWave
|
59
79
|
email:
|
60
80
|
- nowazhu@gmail.com
|
@@ -95,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
115
|
version: '0'
|
96
116
|
requirements: []
|
97
117
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.24
|
99
119
|
signing_key:
|
100
120
|
specification_version: 3
|
101
121
|
summary: UpYun Storage support for CarrierWave
|