carrierwave-aliyun 0.1.1 → 0.1.2

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/Changelogs.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.2
2
+
3
+ * 修正 content_type 的支持,自动用原始文件的 content_type,以免上传 zip 之类的文件以后无法下载.
4
+
1
5
  ## 0.1.1
2
6
 
3
7
  * 修改 Aliyun OSS 的请求地址.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "carrierwave-aliyun"
6
- s.version = "0.1.1"
6
+ s.version = "0.1.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Jason Lee"]
9
9
  s.email = ["huacnlee@gmail.com"]
@@ -1,6 +1,9 @@
1
1
  require "carrierwave/storage/aliyun"
2
+ require 'carrierwave/processing/mime_types'
2
3
  require "carrierwave/aliyun/configuration"
3
4
  CarrierWave.configure do |config|
4
5
  config.storage_engines.merge!({:aliyun => "CarrierWave::Storage::Aliyun"})
5
6
  end
6
- CarrierWave::Uploader::Base.send(:include, CarrierWave::Aliyun::Configuration)
7
+ CarrierWave::Uploader::Base.send(:include, CarrierWave::Aliyun::Configuration)
8
+ CarrierWave::Uploader::Base.send(:include, CarrierWave::MimeTypes)
9
+ CarrierWave::Uploader::Base.send(:process, :set_content_type)
@@ -18,10 +18,10 @@ module CarrierWave
18
18
  @aliyun_host = "oss-internal.aliyuncs.com"
19
19
  end
20
20
  end
21
-
22
- def put(path, file)
21
+
22
+ def put(path, file, options={})
23
23
  content_md5 = Digest::MD5.hexdigest(file)
24
- content_type = "image/jpg"
24
+ content_type = options[:content_type] || "image/jpg"
25
25
  date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
26
26
  path = "#{@aliyun_bucket}/#{path}"
27
27
  url = "http://#{@aliyun_host}/#{path}"
@@ -100,8 +100,8 @@ module CarrierWave
100
100
  "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
101
101
  end
102
102
 
103
- def store(data)
104
- oss_connection.put(@path, data)
103
+ def store(data, opts = {})
104
+ oss_connection.put(@path, data, opts)
105
105
  end
106
106
 
107
107
  private
@@ -129,7 +129,7 @@ module CarrierWave
129
129
 
130
130
  def store!(file)
131
131
  f = CarrierWave::Storage::Aliyun::File.new(uploader, self, uploader.store_path)
132
- f.store(file.read)
132
+ f.store(file.read, :content_type => file.content_type)
133
133
  f
134
134
  end
135
135
 
data/spec/foo.zip ADDED
Binary file
data/spec/upload_spec.rb CHANGED
@@ -9,6 +9,10 @@ describe "Upload" do
9
9
  create_table :photos do |t|
10
10
  t.column :image, :string
11
11
  end
12
+
13
+ create_table :attachments do |t|
14
+ t.column :file, :string
15
+ end
12
16
  end
13
17
  end
14
18
 
@@ -29,11 +33,23 @@ describe "Upload" do
29
33
  "photos"
30
34
  end
31
35
  end
36
+
37
+ class AttachUploader < CarrierWave::Uploader::Base
38
+ include CarrierWave::MiniMagick
39
+
40
+ def store_dir
41
+ "attachs"
42
+ end
43
+ end
32
44
 
33
45
  class Photo < ActiveRecord::Base
34
46
  mount_uploader :image, PhotoUploader
35
47
  end
36
48
 
49
+ class Attachment < ActiveRecord::Base
50
+ mount_uploader :file, AttachUploader
51
+ end
52
+
37
53
 
38
54
  before :all do
39
55
  setup_db
@@ -69,5 +85,22 @@ describe "Upload" do
69
85
  open(@photo1.image.small.url).should_not == nil
70
86
  end
71
87
  end
88
+
89
+ context "should update zip" do
90
+ before(:all) do
91
+ @file = load_file("foo.zip")
92
+ @attachment = Attachment.new(:file => @file)
93
+ end
94
+
95
+ it "should upload file" do
96
+ @attachment.save.should be_true
97
+ end
98
+
99
+ it "should get uploaded file" do
100
+ attach = open(@attachment.file.url)
101
+ attach.size.should == @file.size
102
+ end
103
+
104
+ end
72
105
  end
73
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-27 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
16
+ prerelease: false
16
17
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.5.7
22
+ none: false
22
23
  type: :runtime
23
- prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: 0.5.7
29
+ none: false
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rest-client
32
+ prerelease: false
32
33
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: 1.6.7
38
+ none: false
38
39
  type: :runtime
39
- prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: 1.6.7
45
+ none: false
46
46
  description: Aliyun OSS support for Carrierwave
47
47
  email:
48
48
  - huacnlee@gmail.com
@@ -62,6 +62,7 @@ files:
62
62
  - lib/carrierwave/storage/aliyun.rb
63
63
  - spec/foo.gif
64
64
  - spec/foo.jpg
65
+ - spec/foo.zip
65
66
  - spec/spec_helper.rb
66
67
  - spec/upload_spec.rb
67
68
  homepage: https://github.com/nowa/carrierwave-aliyun
@@ -71,17 +72,17 @@ rdoc_options: []
71
72
  require_paths:
72
73
  - lib
73
74
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
75
  requirements:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
79
  none: false
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ! '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
+ none: false
85
86
  requirements: []
86
87
  rubyforge_project:
87
88
  rubygems_version: 1.8.24
@@ -91,6 +92,6 @@ summary: Aliyun OSS support for Carrierwave
91
92
  test_files:
92
93
  - spec/foo.gif
93
94
  - spec/foo.jpg
95
+ - spec/foo.zip
94
96
  - spec/spec_helper.rb
95
97
  - spec/upload_spec.rb
96
- has_rdoc: