From e2b5faf50ae9908b7fe62c3b00536f490a8f15a3 Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Tue, 30 Aug 2011 08:32:32 -0500 Subject: [PATCH] Shorten mime-types section in readme --- README.md | 59 ++++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 074f86b43..1b5c8414f 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,23 @@ contain Russian letters: Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party plugins or client-side software. +## Setting the content type + +If care about the content type of your files and notice that it's not being set +as expected, you can configure your uploaders to use `CarrierWave::MimeTypes`. +This adds a dependency on the [mime-types](http://rubygems.org/gems/mime-types) gem, +but is recommended when using fog, and fog already has a dependency on mime-types. + +``` ruby +require 'carrierwave/processing/mime_types' + +class MyUploader < CarrierWave::Uploader::Base + include CarrierWave::MimeTypes + + processor :set_content_type +end +``` + ## Adding versions Often you'll want to add different versions of the same file. The classic @@ -217,48 +234,6 @@ class MyUploader < CarrierWave::Uploader::Base end ``` -## File Content-Types - -CarrierWave tries to determine a file's content-type automatically. This is -done by attempting to call `content_type` on the file, and examining the -file's extension. If neither approach results in an estimated content-type, -CarrierWave leaves the file's content-type as `nil`. - -In Rails applications, form params usually provide the file's content-type. -CarrierWave will pick up that content-type automatically, and pass to the -storage service (Eg: Fog). - -### Setting Specific Content-Types - -If you're finding that your files' content-type is not being set correctly, -you can configure your uploaders to use `CarrierWave::MimeTypes`. This will -examine the file's contents and determine the correct content-type. To do -this, first require `carrierwave/processing/mime_types`. Eg: - -``` ruby -require 'carrierwave/processing/mime_types' -``` - -Next, include `CarrierWave::MimeTypes` in your uploader, and add the -_set_content_type_ processor to your uploader. Eg: - -``` ruby -class MyUploader < CarrierWave::Uploader::Base - include CarrierWave::MimeTypes - - processor :set_content_type -end -``` - -In Rails applications, the `require` is often put in an initializer. - -Note that this adds a dependency on the [mime gem](http://rubygems.org/gems/mime) . - -Typically, this should only matter if: - -1. You care about the content-type. -2. You're storing your files in a Fog-backed storage service, such as S3. - ## Making uploads work across form redisplays Often you'll notice that uploaded files disappear when a validation fails.