Skip to content

Commit

Permalink
Shorten mime-types section in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorturk committed Aug 30, 2011
1 parent b2c2bf9 commit e2b5faf
Showing 1 changed file with 17 additions and 42 deletions.
59 changes: 17 additions & 42 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e2b5faf

Please sign in to comment.