carrierwave_direct 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +49 -2
- data/lib/carrierwave_direct.rb +2 -1
- data/lib/carrierwave_direct/uploader.rb +4 -3
- data/lib/carrierwave_direct/uploader/configuration.rb +1 -0
- data/lib/carrierwave_direct/version.rb +1 -1
- data/spec/uploader_spec.rb +4 -0
- metadata +3 -3
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -68,7 +68,10 @@ Remove the line `storage :file` and replace it with `include CarrierWaveDirect::
|
|
68
68
|
|
69
69
|
This adds the extra functionality for direct uploading.
|
70
70
|
|
71
|
-
|
71
|
+
**Optional**: Remove the `store_dir` method in order to default CarrierWaveDirect to its own storage directory.
|
72
|
+
|
73
|
+
/uploads/<unique_guid>/foo.png
|
74
|
+
|
72
75
|
|
73
76
|
If you're *not* using Rails you can generate a direct upload form to S3 similar to [this example](http://doc.s3.amazonaws.com/proposals/post.html#A_Sample_Form)) by making use of the CarrierWaveDirect helper methods.
|
74
77
|
|
@@ -134,6 +137,10 @@ things just got a whole lot easier. You can generate a direct upload form like t
|
|
134
137
|
<%= f.submit %>
|
135
138
|
<% end %>
|
136
139
|
|
140
|
+
After uploading to S3, You'll need to update the uploader object with the returned key in the controller action that corresponds to `new_user_url`:
|
141
|
+
|
142
|
+
@uploader.update_attribute :key, params[:key]
|
143
|
+
|
137
144
|
You can also pass html options like this:
|
138
145
|
|
139
146
|
<%= direct_upload_form_for @uploader, :html => { :target => "_blank_iframe" } do |f| %>
|
@@ -163,6 +170,37 @@ Note if you're using Rails 3.0.x you'll also need to disable forgery protection
|
|
163
170
|
|
164
171
|
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
172
|
|
173
|
+
## Content-Type / Mime
|
174
|
+
|
175
|
+
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).
|
176
|
+
|
177
|
+
First, tell CarrierWaveDirect that you will include your content type manually by adding to your initializer:
|
178
|
+
|
179
|
+
CarrierWave.configure do |config|
|
180
|
+
# ... fog configuration and other options ...
|
181
|
+
config.will_include_content_type = true
|
182
|
+
end
|
183
|
+
|
184
|
+
Then, just add a content-type element to the form.
|
185
|
+
|
186
|
+
<%= direct_upload_form_for @uploader do |f| %>
|
187
|
+
<%= text_field_tag 'Content-Type', 'video/mpeg' %><br>
|
188
|
+
<%= f.file_field :avatar %>
|
189
|
+
<%= f.submit %>
|
190
|
+
<% end %>
|
191
|
+
|
192
|
+
You could use a select as well.
|
193
|
+
|
194
|
+
<%= direct_upload_form_for @uploader do |f| %>
|
195
|
+
<%= select_tag 'Content-Type', options_for_select([
|
196
|
+
['Video','video/mpeg'],
|
197
|
+
['Audio','audio/mpeg'],
|
198
|
+
['Image','image/jpeg']
|
199
|
+
], 'video/mpeg') %><br>
|
200
|
+
<%= f.file_field :avatar %>
|
201
|
+
<%= f.submit %>
|
202
|
+
<% end %>
|
203
|
+
|
166
204
|
## Processing and referencing files in a background process
|
167
205
|
|
168
206
|
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).
|
@@ -294,6 +332,9 @@ As well as the built in validations CarrierWaveDirect provides, some validations
|
|
294
332
|
config.min_file_size = 5.kilobytes # defaults to 1.byte
|
295
333
|
config.max_file_size = 10.megabytes # defaults to 5.megabytes
|
296
334
|
config.upload_expiration = 1.hour # defaults to 10.hours
|
335
|
+
config.will_include_content_type = true # defaults to false; if true, content-type will be set
|
336
|
+
# on s3, but you must include an input field named
|
337
|
+
# Content-Type on every direct upload form
|
297
338
|
end
|
298
339
|
|
299
340
|
## Testing with CarrierWaveDirect
|
@@ -388,7 +429,7 @@ If you're Rails app was newly generated *after* version 3.2.3 and your testing t
|
|
388
429
|
|
389
430
|
## Contributing to CarrierWaveDirect
|
390
431
|
|
391
|
-
Pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested.
|
432
|
+
Pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested. Pull requests without tests *will not* be accepted.
|
392
433
|
|
393
434
|
gem install bundler
|
394
435
|
bundle install
|
@@ -397,6 +438,10 @@ You should now be able to run the tests
|
|
397
438
|
|
398
439
|
bundle exec rake
|
399
440
|
|
441
|
+
### Using the Sample Application
|
442
|
+
|
443
|
+
After you have fixed a bug or added a feature please also use the [CarrierWaveDirect Sample Application](https://github.com/dwilkie/carrierwave_direct_example) to ensure that the gem still works correctly.
|
444
|
+
|
400
445
|
## Contributors
|
401
446
|
|
402
447
|
* [cblunt (Chris Blunt)](https://github.com/cblunt) - Support for passing html options
|
@@ -415,3 +460,5 @@ You should now be able to run the tests
|
|
415
460
|
* [kylecrum (Kyle Crum)](https://github.com/kylecrum) - Fix double url encoding bug
|
416
461
|
* [rsniezynski](https://github.com/rsniezynski) - Add min file size configuration
|
417
462
|
* [philipp-spiess (Philipp Spieß)](https://github.com/philipp-spiess) - Direct fog url bugfix
|
463
|
+
* [colinyoung (Colin Young)](https://github.com/colinyoung) - Content-Type support
|
464
|
+
* [filiptepper (Filip Tepper)](https://github.com/filiptepper) - Autoload UUID on heroku
|
data/lib/carrierwave_direct.rb
CHANGED
@@ -61,13 +61,14 @@ module CarrierWaveDirect
|
|
61
61
|
options[:expiration] ||= self.class.upload_expiration
|
62
62
|
options[:min_file_size] ||= self.class.min_file_size
|
63
63
|
options[:max_file_size] ||= self.class.max_file_size
|
64
|
+
|
65
|
+
conditions = [ ["starts-with", "$utf8", ""], ["starts-with", "$key", store_dir] ]
|
66
|
+
conditions << ["starts-with", "$Content-Type", ""] if self.class.will_include_content_type
|
64
67
|
|
65
68
|
Base64.encode64(
|
66
69
|
{
|
67
70
|
'expiration' => Time.now.utc + options[:expiration],
|
68
|
-
'conditions' => [
|
69
|
-
["starts-with", "$utf8", ""],
|
70
|
-
["starts-with", "$key", store_dir],
|
71
|
+
'conditions' => conditions + [
|
71
72
|
{"bucket" => fog_directory},
|
72
73
|
{"acl" => acl},
|
73
74
|
{"success_action_redirect" => success_action_redirect},
|
data/spec/uploader_spec.rb
CHANGED
@@ -434,6 +434,10 @@ describe CarrierWaveDirect::Uploader do
|
|
434
434
|
subject.success_action_redirect = "http://example.com/some_url"
|
435
435
|
conditions.should have_condition("success_action_redirect" => "http://example.com/some_url")
|
436
436
|
end
|
437
|
+
|
438
|
+
it "'content-type' only if enabled" do
|
439
|
+
conditions.should have_condition('Content-Type') if subject.class.will_include_content_type
|
440
|
+
end
|
437
441
|
|
438
442
|
context "'content-length-range of'" do
|
439
443
|
def have_content_length_range(options = {})
|
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.
|
4
|
+
version: 0.0.11
|
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-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
segments:
|
204
204
|
- 0
|
205
|
-
hash:
|
205
|
+
hash: 681164957
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project: carrierwave_direct
|
208
208
|
rubygems_version: 1.8.24
|