carrierwave-aliyun-crud 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -3
- data/lib/carrierwave-aliyun-crud.rb +2 -0
- data/lib/carrierwave/storage/aliyun.rb +4 -3
- metadata +6 -22
- data/.gitignore +0 -2
- data/.rspec +0 -1
- data/Changelogs.md +0 -12
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -114
- data/carrierwave-aliyun-crud.gemspec +0 -20
- data/spec/foo.gif +0 -0
- data/spec/foo.jpg +0 -0
- data/spec/foo.zip +0 -0
- data/spec/spec_helper.rb +0 -37
- data/spec/upload_spec.rb +0 -112
data/README.md
CHANGED
@@ -17,16 +17,30 @@ gem 'carrierwave-aliyun-crud'
|
|
17
17
|
|
18
18
|
## Configuration
|
19
19
|
|
20
|
-
|
20
|
+
创建脚本 `config/initializes/carrierwave.rb` 填入下面的代码,并修改对应的配置:
|
21
21
|
|
22
22
|
```ruby
|
23
23
|
CarrierWave.configure do |config|
|
24
24
|
config.storage = :aliyun
|
25
25
|
config.aliyun_access_id = "xxxxxx"
|
26
26
|
config.aliyun_access_key = 'xxxxxx'
|
27
|
-
#
|
27
|
+
# 需要在 Aliyum OSS 上面提前创建一个 Bucket
|
28
28
|
config.aliyun_bucket = "simple"
|
29
29
|
# 是否使用内部连接,true - 使用 Aliyun 局域网的方式访问 false - 外部网络访问
|
30
30
|
config.aliyun_internal = true
|
31
31
|
end
|
32
|
-
```
|
32
|
+
```
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
上传文件
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
CarrierWave::Storage::Aliyun::Connection.new(options).put relative_store_url, File.read(file_path)
|
39
|
+
```
|
40
|
+
|
41
|
+
删除文件
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
CarrierWave::Storage::Aliyun::Connection.new(options).delete relative_store_url
|
45
|
+
#如果删除的文件不存在,不会有异常
|
46
|
+
```
|
@@ -4,6 +4,7 @@ require 'digest/hmac'
|
|
4
4
|
require 'digest/md5'
|
5
5
|
require 'net/http'
|
6
6
|
require "rest-client"
|
7
|
+
require 'uri'
|
7
8
|
|
8
9
|
module CarrierWave
|
9
10
|
module Storage
|
@@ -26,14 +27,14 @@ module CarrierWave
|
|
26
27
|
path = "#{@aliyun_bucket}/#{path}"
|
27
28
|
url = "http://#{@aliyun_host}/#{path}"
|
28
29
|
headers = generate_header("PUT", path, content_md5, options).merge!({"Content-Length" => file.length})
|
29
|
-
RestClient.put url, file, headers
|
30
|
+
RestClient.put URI.escape(url), file, headers
|
30
31
|
end
|
31
32
|
|
32
33
|
def get(path, options={})
|
33
34
|
path = "#{@aliyun_bucket}/#{path}"
|
34
35
|
url = "http://#{@aliyun_host}/#{path}"
|
35
36
|
headers = generate_header "GET", path, "", options
|
36
|
-
RestClient.get url, headers
|
37
|
+
RestClient.get URI.escape(url), headers
|
37
38
|
end
|
38
39
|
|
39
40
|
def delete path
|
@@ -45,7 +46,7 @@ module CarrierWave
|
|
45
46
|
"Date" => date,
|
46
47
|
"Host" => @aliyun_host,
|
47
48
|
}
|
48
|
-
RestClient.delete url, headers
|
49
|
+
RestClient.delete URI.escape(url), headers
|
49
50
|
end
|
50
51
|
|
51
52
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-aliyun-crud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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: 2013-
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -50,21 +50,10 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .rspec
|
55
|
-
- Changelogs.md
|
56
|
-
- Gemfile
|
57
|
-
- Gemfile.lock
|
58
|
-
- README.md
|
59
|
-
- carrierwave-aliyun-crud.gemspec
|
60
|
-
- lib/carrierwave-aliyun-crud.rb
|
61
53
|
- lib/carrierwave/aliyun/configuration.rb
|
62
54
|
- lib/carrierwave/storage/aliyun.rb
|
63
|
-
-
|
64
|
-
-
|
65
|
-
- spec/foo.zip
|
66
|
-
- spec/spec_helper.rb
|
67
|
-
- spec/upload_spec.rb
|
55
|
+
- lib/carrierwave-aliyun-crud.rb
|
56
|
+
- README.md
|
68
57
|
homepage: https://github.com/warmwind/carrierwave-aliyun-crud
|
69
58
|
licenses: []
|
70
59
|
post_install_message:
|
@@ -85,13 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
74
|
version: '0'
|
86
75
|
requirements: []
|
87
76
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.23
|
89
78
|
signing_key:
|
90
79
|
specification_version: 3
|
91
80
|
summary: Aliyun OSS support for Carrierwave
|
92
|
-
test_files:
|
93
|
-
- spec/foo.gif
|
94
|
-
- spec/foo.jpg
|
95
|
-
- spec/foo.zip
|
96
|
-
- spec/spec_helper.rb
|
97
|
-
- spec/upload_spec.rb
|
81
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour --format nested
|
data/Changelogs.md
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://ruby.taobao.org/
|
3
|
-
specs:
|
4
|
-
actionmailer (3.2.1)
|
5
|
-
actionpack (= 3.2.1)
|
6
|
-
mail (~> 2.4.0)
|
7
|
-
actionpack (3.2.1)
|
8
|
-
activemodel (= 3.2.1)
|
9
|
-
activesupport (= 3.2.1)
|
10
|
-
builder (~> 3.0.0)
|
11
|
-
erubis (~> 2.7.0)
|
12
|
-
journey (~> 1.0.1)
|
13
|
-
rack (~> 1.4.0)
|
14
|
-
rack-cache (~> 1.1)
|
15
|
-
rack-test (~> 0.6.1)
|
16
|
-
sprockets (~> 2.1.2)
|
17
|
-
activemodel (3.2.1)
|
18
|
-
activesupport (= 3.2.1)
|
19
|
-
builder (~> 3.0.0)
|
20
|
-
activerecord (3.2.1)
|
21
|
-
activemodel (= 3.2.1)
|
22
|
-
activesupport (= 3.2.1)
|
23
|
-
arel (~> 3.0.0)
|
24
|
-
tzinfo (~> 0.3.29)
|
25
|
-
activeresource (3.2.1)
|
26
|
-
activemodel (= 3.2.1)
|
27
|
-
activesupport (= 3.2.1)
|
28
|
-
activesupport (3.2.1)
|
29
|
-
i18n (~> 0.6)
|
30
|
-
multi_json (~> 1.0)
|
31
|
-
arel (3.0.0)
|
32
|
-
builder (3.0.0)
|
33
|
-
carrierwave (0.5.8)
|
34
|
-
activesupport (~> 3.0)
|
35
|
-
diff-lcs (1.1.3)
|
36
|
-
erubis (2.7.0)
|
37
|
-
hike (1.2.1)
|
38
|
-
i18n (0.6.0)
|
39
|
-
journey (1.0.1)
|
40
|
-
json (1.6.5)
|
41
|
-
mail (2.4.1)
|
42
|
-
i18n (>= 0.4.0)
|
43
|
-
mime-types (~> 1.16)
|
44
|
-
treetop (~> 1.4.8)
|
45
|
-
metaclass (0.0.1)
|
46
|
-
mime-types (1.17.2)
|
47
|
-
mini_magick (3.4)
|
48
|
-
subexec (~> 0.2.1)
|
49
|
-
mocha (0.10.0)
|
50
|
-
metaclass (~> 0.0.1)
|
51
|
-
multi_json (1.0.4)
|
52
|
-
polyglot (0.3.3)
|
53
|
-
rack (1.4.1)
|
54
|
-
rack-cache (1.1)
|
55
|
-
rack (>= 0.4)
|
56
|
-
rack-ssl (1.3.2)
|
57
|
-
rack
|
58
|
-
rack-test (0.6.1)
|
59
|
-
rack (>= 1.0)
|
60
|
-
rails (3.2.1)
|
61
|
-
actionmailer (= 3.2.1)
|
62
|
-
actionpack (= 3.2.1)
|
63
|
-
activerecord (= 3.2.1)
|
64
|
-
activeresource (= 3.2.1)
|
65
|
-
activesupport (= 3.2.1)
|
66
|
-
bundler (~> 1.0)
|
67
|
-
railties (= 3.2.1)
|
68
|
-
railties (3.2.1)
|
69
|
-
actionpack (= 3.2.1)
|
70
|
-
activesupport (= 3.2.1)
|
71
|
-
rack-ssl (~> 1.3.2)
|
72
|
-
rake (>= 0.8.7)
|
73
|
-
rdoc (~> 3.4)
|
74
|
-
thor (~> 0.14.6)
|
75
|
-
rake (0.9.2.2)
|
76
|
-
rdoc (3.12)
|
77
|
-
json (~> 1.4)
|
78
|
-
rest-client (1.6.7)
|
79
|
-
mime-types (>= 1.16)
|
80
|
-
rspec (2.6.0)
|
81
|
-
rspec-core (~> 2.6.0)
|
82
|
-
rspec-expectations (~> 2.6.0)
|
83
|
-
rspec-mocks (~> 2.6.0)
|
84
|
-
rspec-core (2.6.4)
|
85
|
-
rspec-expectations (2.6.0)
|
86
|
-
diff-lcs (~> 1.1.2)
|
87
|
-
rspec-mocks (2.6.0)
|
88
|
-
sprockets (2.1.2)
|
89
|
-
hike (~> 1.2)
|
90
|
-
rack (~> 1.0)
|
91
|
-
tilt (~> 1.1, != 1.3.0)
|
92
|
-
sqlite3 (1.3.5)
|
93
|
-
sqlite3-ruby (1.3.3)
|
94
|
-
sqlite3 (>= 1.3.3)
|
95
|
-
subexec (0.2.1)
|
96
|
-
thor (0.14.6)
|
97
|
-
tilt (1.3.3)
|
98
|
-
treetop (1.4.10)
|
99
|
-
polyglot
|
100
|
-
polyglot (>= 0.3.1)
|
101
|
-
tzinfo (0.3.31)
|
102
|
-
|
103
|
-
PLATFORMS
|
104
|
-
ruby
|
105
|
-
|
106
|
-
DEPENDENCIES
|
107
|
-
carrierwave
|
108
|
-
mini_magick
|
109
|
-
mocha (= 0.10.0)
|
110
|
-
rails
|
111
|
-
rake
|
112
|
-
rest-client
|
113
|
-
rspec (~> 2.6.0)
|
114
|
-
sqlite3-ruby
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "carrierwave-aliyun-crud"
|
6
|
-
s.version = "0.1.0"
|
7
|
-
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = ["Jiang Peng"]
|
9
|
-
s.email = ["pengj0520@gmail.com"]
|
10
|
-
s.homepage = "https://github.com/warmwind/carrierwave-aliyun-crud"
|
11
|
-
s.summary = %q{Aliyun OSS support for Carrierwave}
|
12
|
-
s.description = %q{Aliyun OSS support for Carrierwave}
|
13
|
-
s.files = `git ls-files`.split("\n")
|
14
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
|
18
|
-
s.add_dependency "carrierwave", [">= 0.5.7"]
|
19
|
-
s.add_dependency "rest-client", [">= 1.6.7"]
|
20
|
-
end
|
data/spec/foo.gif
DELETED
Binary file
|
data/spec/foo.jpg
DELETED
Binary file
|
data/spec/foo.zip
DELETED
Binary file
|
data/spec/spec_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rspec'
|
3
|
-
require 'rspec/autorun'
|
4
|
-
require 'rails'
|
5
|
-
require 'active_record'
|
6
|
-
require "carrierwave"
|
7
|
-
require 'carrierwave/orm/activerecord'
|
8
|
-
require 'carrierwave/processing/mini_magick'
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
12
|
-
|
13
|
-
require "carrierwave-aliyun-crud"
|
14
|
-
|
15
|
-
|
16
|
-
module Rails
|
17
|
-
class <<self
|
18
|
-
def root
|
19
|
-
[File.expand_path(__FILE__).split('/')[0..-3].join('/'),"spec"].join("/")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
ActiveRecord::Migration.verbose = false
|
25
|
-
|
26
|
-
# 测试的时候需要修改这个地方
|
27
|
-
CarrierWave.configure do |config|
|
28
|
-
config.storage = :aliyun
|
29
|
-
config.aliyun_access_id = "n4R7XBeTZqd2blQz"
|
30
|
-
config.aliyun_access_key = 'WiMTt42rLMT9bPGfGaEaNlzHahG9du'
|
31
|
-
config.aliyun_bucket = "carrierwave-jp"
|
32
|
-
config.aliyun_internal = false
|
33
|
-
end
|
34
|
-
|
35
|
-
def load_file(fname)
|
36
|
-
File.open([Rails.root,fname].join("/"))
|
37
|
-
end
|
data/spec/upload_spec.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
require "open-uri"
|
4
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
5
|
-
|
6
|
-
describe "Upload" do
|
7
|
-
def setup_db
|
8
|
-
ActiveRecord::Schema.define(:version => 1) do
|
9
|
-
create_table :photos do |t|
|
10
|
-
t.column :image, :string
|
11
|
-
end
|
12
|
-
|
13
|
-
create_table :attachments do |t|
|
14
|
-
t.column :file, :string
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def drop_db
|
20
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
21
|
-
ActiveRecord::Base.connection.drop_table(table)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class PhotoUploader < CarrierWave::Uploader::Base
|
26
|
-
include CarrierWave::MiniMagick
|
27
|
-
|
28
|
-
version :small do
|
29
|
-
process :resize_to_fill => [120, 120]
|
30
|
-
end
|
31
|
-
|
32
|
-
def store_dir
|
33
|
-
"photos"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class AttachUploader < CarrierWave::Uploader::Base
|
38
|
-
include CarrierWave::MiniMagick
|
39
|
-
|
40
|
-
def store_dir
|
41
|
-
"attachs"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Photo < ActiveRecord::Base
|
46
|
-
mount_uploader :image, PhotoUploader
|
47
|
-
end
|
48
|
-
|
49
|
-
class Attachment < ActiveRecord::Base
|
50
|
-
mount_uploader :file, AttachUploader
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
before :all do
|
55
|
-
setup_db
|
56
|
-
end
|
57
|
-
|
58
|
-
after :all do
|
59
|
-
drop_db
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "Upload Image" do
|
63
|
-
context "should upload image" do
|
64
|
-
before(:all) do
|
65
|
-
@file = load_file("foo.jpg")
|
66
|
-
@file1 = load_file("foo.gif")
|
67
|
-
@photo = Photo.new(:image => @file)
|
68
|
-
@photo1 = Photo.new(:image => @file1)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should upload file" do
|
72
|
-
@photo.save.should be_true
|
73
|
-
@photo1.save.should be_true
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should get uploaded file" do
|
77
|
-
img = open(@photo.image.url)
|
78
|
-
img.size.should == @file.size
|
79
|
-
img1 = open(@photo1.image.url)
|
80
|
-
img1.size.should == @file1.size
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should get small version uploaded file" do
|
84
|
-
open(@photo.image.small.url).should_not == nil
|
85
|
-
open(@photo1.image.small.url).should_not == nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should delete uploaded files" do
|
89
|
-
@photo.remove_image!
|
90
|
-
@photo.reload
|
91
|
-
expect {open(@photo.image.url)}.to raise_error(OpenURI::HTTPError)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "should update zip" do
|
96
|
-
before(:all) do
|
97
|
-
@file = load_file("foo.zip")
|
98
|
-
@attachment = Attachment.new(:file => @file)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should upload file" do
|
102
|
-
@attachment.save.should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should get uploaded file" do
|
106
|
-
attach = open(@attachment.file.url)
|
107
|
-
attach.size.should == @file.size
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|