carrierwave_direct 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  .rvmrc
5
5
  pkg/*
6
+ vendor/ruby
data/.travis.yml CHANGED
@@ -1,4 +1,2 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
-
2
+ - 1.9.3
data/README.md CHANGED
@@ -163,6 +163,30 @@ Note if you're using Rails 3.0.x you'll also need to disable forgery protection
163
163
 
164
164
  Once you've uploaded your file directly to the cloud you'll probably need a way to reference it with an ORM and process it.
165
165
 
166
+ ## Content-Type / Mime
167
+
168
+ The default amazon content-type is "binary/octet-stream" and for many cases this will work just fine. But if you are trying to stream video or audio you will need to set the mime type manually as Amazon will not calculate it for you. All mime types are supported: [http://en.wikipedia.org/wiki/Internet_media_type](http://en.wikipedia.org/wiki/Internet_media_type).
169
+
170
+ Just add a content-type element to the form.
171
+
172
+ <%= direct_upload_form_for @uploader do |f| %>
173
+ <%= text_field_tag 'Content-Type', 'video/mpeg' %><br>
174
+ <%= f.file_field :avatar %>
175
+ <%= f.submit %>
176
+ <% end %>
177
+
178
+ You could use a select as well.
179
+
180
+ <%= direct_upload_form_for @uploader do |f| %>
181
+ <%= select_tag 'Content-Type', options_for_select([
182
+ ['Video','video/mpeg'],
183
+ ['Audio','audio/mpeg'],
184
+ ['Image','image/jpeg']
185
+ ], 'video/mpeg') %><br>
186
+ <%= f.file_field :avatar %>
187
+ <%= f.submit %>
188
+ <% end %>
189
+
166
190
  ## Processing and referencing files in a background process
167
191
 
168
192
  Processing and saving file uploads are typically long running tasks and should be done in a background process. CarrierWaveDirect gives you a few methods to help you do this with your favorite background processor such as [DelayedJob](https://github.com/collectiveidea/delayed_job) or [Resque](https://github.com/defunkt/resque).
@@ -291,6 +315,7 @@ As well as the built in validations CarrierWaveDirect provides, some validations
291
315
  config.validate_filename_format = false # defaults to true
292
316
  config.validate_remote_net_url_format = false # defaults to true
293
317
 
318
+ config.min_file_size = 5.kilobytes # defaults to 1.byte
294
319
  config.max_file_size = 10.megabytes # defaults to 5.megabytes
295
320
  config.upload_expiration = 1.hour # defaults to 10.hours
296
321
  end
@@ -409,3 +434,9 @@ You should now be able to run the tests
409
434
  * [rhalff (Rob Halff)](https://github.com/rhalff) - Doc fix
410
435
  * [nicknovitski (Nick Novitski)](https://github.com/nicknovitski) - Update old link in README
411
436
  * [gabrielengel (Gabriel Engel)](https://github.com/gabrielengel) - Refactor I18n not to use procs
437
+ * [evanlok](https://github.com/evanlok) - Don't be case sensitive with filename extension validation
438
+ * [jkamenik (John Kamenik)](https://github.com/jkamenik) - Support for Content-Type
439
+ * [davesherratt (Dave Sherratt)](https://github.com/davesherratt) - Initial support for Rails 4 strong parameters
440
+ * [kylecrum (Kyle Crum)](https://github.com/kylecrum) - Fix double url encoding bug
441
+ * [rsniezynski](https://github.com/rsniezynski) - Add min file size configuration
442
+ * [philipp-spiess (Philipp Spieß)](https://github.com/philipp-spiess) - Direct fog url bugfix
@@ -7,9 +7,10 @@ Gem::Specification.new do |s|
7
7
  s.version = CarrierwaveDirect::VERSION
8
8
  s.authors = ["David Wilkie"]
9
9
  s.email = ["dwilkie@gmail.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/dwilkie/carrierwave_direct"
11
11
  s.summary = %q{Upload direct to S3 using CarrierWave}
12
12
  s.description = %q{Process your uploads in the background by uploading directly to S3}
13
+ s.required_ruby_version = ">= 1.9.0"
13
14
 
14
15
  s.rubyforge_project = "carrierwave_direct"
15
16
 
@@ -19,7 +20,7 @@ Gem::Specification.new do |s|
19
20
 
20
21
  s.add_development_dependency "rspec"
21
22
  s.add_development_dependency "timecop"
22
- s.add_development_dependency "rails"
23
+ s.add_development_dependency "rails", ">= 3.2.12"
23
24
  s.add_development_dependency "sqlite3"
24
25
  s.add_development_dependency "capybara"
25
26
 
@@ -28,4 +29,3 @@ Gem::Specification.new do |s|
28
29
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
30
  s.require_paths = ["lib"]
30
31
  end
31
-
@@ -31,7 +31,9 @@ module CarrierWaveDirect
31
31
 
32
32
  self.instance_eval <<-RUBY, __FILE__, __LINE__+1
33
33
  attr_accessor :skip_is_attached_validations
34
- attr_accessible :key, :remote_#{column}_net_url
34
+ unless defined?(ActiveModel::ForbiddenAttributesProtection) && ancestors.include?(ActiveModel::ForbiddenAttributesProtection)
35
+ attr_accessible :key, :remote_#{column}_net_url
36
+ end
35
37
  RUBY
36
38
 
37
39
  mod = Module.new
@@ -23,8 +23,8 @@ module CarrierWaveDirect
23
23
  fog_uri = CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
24
24
  if options[:with_path]
25
25
  uri = URI.parse(fog_uri)
26
- path = "/#{key}"
27
- uri.path = URI.escape(path)
26
+ path = "#{key}"
27
+ uri.path += URI.escape(path)
28
28
  fog_uri = uri.to_s
29
29
  end
30
30
  fog_uri
@@ -42,7 +42,7 @@ module CarrierWaveDirect
42
42
  def key
43
43
  return @key if @key.present?
44
44
  if url.present?
45
- self.key = URI.parse(url).path # explicitly set key
45
+ self.key = CGI.unescape(URI.parse(url).path) # explicitly set key
46
46
  else
47
47
  @key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
48
48
  end
@@ -59,18 +59,20 @@ module CarrierWaveDirect
59
59
 
60
60
  def policy(options = {})
61
61
  options[:expiration] ||= self.class.upload_expiration
62
+ options[:min_file_size] ||= self.class.min_file_size
62
63
  options[:max_file_size] ||= self.class.max_file_size
63
64
 
64
65
  Base64.encode64(
65
66
  {
66
67
  'expiration' => Time.now.utc + options[:expiration],
67
68
  'conditions' => [
69
+ ["starts-with", "$Content-Type", ""],
68
70
  ["starts-with", "$utf8", ""],
69
71
  ["starts-with", "$key", store_dir],
70
72
  {"bucket" => fog_directory},
71
73
  {"acl" => acl},
72
74
  {"success_action_redirect" => success_action_redirect},
73
- ["content-length-range", 1, options[:max_file_size]]
75
+ ["content-length-range", options[:min_file_size], options[:max_file_size]]
74
76
  ]
75
77
  }.to_json
76
78
  ).gsub("\n","")
@@ -105,7 +107,7 @@ module CarrierWaveDirect
105
107
  end
106
108
 
107
109
  def key_regexp
108
- /\A#{store_dir}\/[a-f\d\-]+\/.+\.#{extension_regexp}\z/
110
+ /\A#{store_dir}\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
109
111
  end
110
112
 
111
113
  def extension_regexp
@@ -13,6 +13,7 @@ module CarrierWaveDirect
13
13
  add_config :validate_filename_format
14
14
  add_config :validate_remote_net_url_format
15
15
 
16
+ add_config :min_file_size
16
17
  add_config :max_file_size
17
18
  add_config :upload_expiration
18
19
  reset_direct_config
@@ -27,6 +28,7 @@ module CarrierWaveDirect
27
28
  config.validate_filename_format = true
28
29
  config.validate_remote_net_url_format = true
29
30
 
31
+ config.min_file_size = 1
30
32
  config.max_file_size = 5242880
31
33
  config.upload_expiration = 36000
32
34
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CarrierwaveDirect
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
6
6
 
@@ -56,4 +56,3 @@ describe CarrierWaveDirect::FormBuilder do
56
56
  end
57
57
  end
58
58
  end
59
-
@@ -3,7 +3,7 @@
3
3
  require 'action_view'
4
4
  require 'action_view/template'
5
5
 
6
- require File.join(File.dirname(__FILE__), 'view_helpers')
6
+ require File.join(File.dirname(__FILE__), 'view_helpers')
7
7
 
8
8
  require 'carrierwave_direct/form_builder'
9
9
  require 'carrierwave_direct/action_view_extensions/form_helper'
@@ -34,4 +34,3 @@ module FormBuilderHelpers
34
34
  direct_upload_form_for(direct_uploader, options, &blk)
35
35
  end
36
36
  end
37
-
@@ -15,6 +15,7 @@ describe CarrierWaveDirect::Uploader do
15
15
  :extension_regexp => "(avi)",
16
16
  :url => "http://example.com/some_url",
17
17
  :expiration => 60,
18
+ :min_file_size => 1024,
18
19
  :max_file_size => 10485760,
19
20
  :file_url => "http://anyurl.com/any_path/video_dir/filename.avi",
20
21
  :mounted_model_name => "Porno",
@@ -55,6 +56,12 @@ describe CarrierWaveDirect::Uploader do
55
56
  end
56
57
  end
57
58
 
59
+ describe ".min_file_size" do
60
+ it "should be 1 byte" do
61
+ subject.class.min_file_size.should == 1
62
+ end
63
+ end
64
+
58
65
  describe ".max_file_size" do
59
66
  it "should be 5 MB" do
60
67
  subject.class.max_file_size.should == 5242880
@@ -158,7 +165,7 @@ describe CarrierWaveDirect::Uploader do
158
165
  end
159
166
 
160
167
  it "should return /\\A#{sample(:store_dir)}\\/#{GUID_REGEXP}\\/.+\\.#{sample(:extension_regexp)}\\z/" do
161
- subject.key_regexp.should == /\A#{sample(:store_dir)}\/#{GUID_REGEXP}\/.+\.#{sample(:extension_regexp)}\z/
168
+ subject.key_regexp.should == /\A#{sample(:store_dir)}\/#{GUID_REGEXP}\/.+\.(?i)#{sample(:extension_regexp)}(?-i)\z/
162
169
  end
163
170
  end
164
171
  end
@@ -241,7 +248,10 @@ describe CarrierWaveDirect::Uploader do
241
248
  before { subject.key = sample(:path_with_special_chars) }
242
249
 
243
250
  it "should return the full url with '/#{URI.escape(sample(:path_with_special_chars))}' as the path" do
244
- URI.parse(subject.direct_fog_url(:with_path => true)).path.should == "/#{URI.escape(sample(:path_with_special_chars))}"
251
+ direct_fog_url = CarrierWave::Storage::Fog::File.new(
252
+ subject, nil, nil
253
+ ).public_url
254
+ subject.direct_fog_url(:with_path => true).should == direct_fog_url + "#{URI.escape(sample(:path_with_special_chars))}"
245
255
  end
246
256
  end
247
257
 
@@ -249,7 +259,10 @@ describe CarrierWaveDirect::Uploader do
249
259
  before { subject.key = sample(:path) }
250
260
 
251
261
  it "should return the full url with '/#{sample(:path)}' as the path" do
252
- URI.parse(subject.direct_fog_url(:with_path => true)).path.should == "/#{sample(:path)}"
262
+ direct_fog_url = CarrierWave::Storage::Fog::File.new(
263
+ subject, nil, nil
264
+ ).public_url
265
+ subject.direct_fog_url(:with_path => true).should == direct_fog_url + "#{sample(:path)}"
253
266
  end
254
267
  end
255
268
  end
@@ -422,20 +435,38 @@ describe CarrierWaveDirect::Uploader do
422
435
  conditions.should have_condition("success_action_redirect" => "http://example.com/some_url")
423
436
  end
424
437
 
438
+ it "'content-type'" do
439
+ conditions.should have_condition('Content-Type')
440
+ end
441
+
425
442
  context "'content-length-range of'" do
426
443
 
427
- def have_content_length_range(max_file_size = DirectUploader.max_file_size)
428
- include(["content-length-range", 1, max_file_size])
444
+ def have_content_length_range(options = {})
445
+ include([
446
+ "content-length-range",
447
+ options[:min_file_size] || DirectUploader.min_file_size,
448
+ options[:max_file_size] || DirectUploader.max_file_size,
449
+ ])
450
+ end
451
+
452
+ it "#{DirectUploader.min_file_size} bytes" do
453
+ conditions.should have_content_length_range
429
454
  end
430
455
 
431
456
  it "#{DirectUploader.max_file_size} bytes" do
432
457
  conditions.should have_content_length_range
433
458
  end
434
459
 
460
+ it "#{sample(:min_file_size)} bytes when passing {:min_file_size => #{sample(:min_file_size)}}" do
461
+ conditions(
462
+ :min_file_size => sample(:min_file_size)
463
+ ).should have_content_length_range(:min_file_size => sample(:min_file_size))
464
+ end
465
+
435
466
  it "#{sample(:max_file_size)} bytes when passing {:max_file_size => #{sample(:max_file_size)}}" do
436
467
  conditions(
437
468
  :max_file_size => sample(:max_file_size)
438
- ).should have_content_length_range(sample(:max_file_size))
469
+ ).should have_content_length_range(:max_file_size => sample(:max_file_size))
439
470
  end
440
471
  end
441
472
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
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-11-19 00:00:00.000000000Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
16
- requirement: &80672100 !ruby/object:Gem::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'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *80672100
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: uuid
27
- requirement: &80671730 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *80671730
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fog
38
- requirement: &80671380 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *80671380
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &80671060 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *80671060
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: timecop
60
- requirement: &80670780 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,21 +85,31 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *80670780
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rails
71
- requirement: &80670500 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
75
100
  - !ruby/object:Gem::Version
76
- version: '0'
101
+ version: 3.2.12
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *80670500
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 3.2.12
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: sqlite3
82
- requirement: &80670220 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *80670220
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: capybara
93
- requirement: &80669910 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *80669910
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  description: Process your uploads in the background by uploading directly to S3
103
143
  email:
104
144
  - dwilkie@gmail.com
@@ -142,7 +182,7 @@ files:
142
182
  - spec/test/capybara_helpers_spec.rb
143
183
  - spec/test/helpers_spec.rb
144
184
  - spec/uploader_spec.rb
145
- homepage: ''
185
+ homepage: https://github.com/dwilkie/carrierwave_direct
146
186
  licenses: []
147
187
  post_install_message:
148
188
  rdoc_options: []
@@ -153,10 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
193
  requirements:
154
194
  - - ! '>='
155
195
  - !ruby/object:Gem::Version
156
- version: '0'
157
- segments:
158
- - 0
159
- hash: 763991155
196
+ version: 1.9.0
160
197
  required_rubygems_version: !ruby/object:Gem::Requirement
161
198
  none: false
162
199
  requirements:
@@ -165,10 +202,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
202
  version: '0'
166
203
  segments:
167
204
  - 0
168
- hash: 763991155
205
+ hash: 353468527
169
206
  requirements: []
170
207
  rubyforge_project: carrierwave_direct
171
- rubygems_version: 1.8.10
208
+ rubygems_version: 1.8.24
172
209
  signing_key:
173
210
  specification_version: 3
174
211
  summary: Upload direct to S3 using CarrierWave