The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
The complete [RDoc](http://rdoc.info/gems/paperclip) is online.
---
Requirements
Requirements
------------
------------
...
@@ -55,12 +56,46 @@ GhostScript to be installed. On Mac OS X, you can also install that using Homebr
...
@@ -55,12 +56,46 @@ GhostScript to be installed. On Mac OS X, you can also install that using Homebr
brew install gs
brew install gs
### `file` command
### `file`
The Unix [`file` command](http://en.wikipedia.org/wiki/File_(command)) is required for content type checking.
The Unix [`file` command](http://en.wikipedia.org/wiki/File_(command)) is required for content type checking.
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
so Windows users must make sure that the devkit is installed and added to system `PATH`.
so Windows users must make sure that the devkit is installed and added to system `PATH`.
**Manual Installation**
If you're using Windows 7+ as a development environment, you may need to install the `file.exe` application manually. The `file spoofing` system in Paperclip 4+ relies on this; if you don't have it working, you'll receive `Validation failed: Upload file has an extension that does not match its contents.` errors.
To manually install, you should perform the following:
> **Download & install `file` from [this URL](http://gnuwin32.sourceforge.net/packages/file.htm)**
Next, you need to integrate with your environment - preferrably through the `PATH` variable, or by changing your `config/environments/development.rb` file
**PATH**
1. Click "Start"
2. On "Computer", right-click and select "Properties"
3. In properties, select "Advanced System Settings"
4. Click the "Environment Variables" button
5. Locate the "PATH" var - at the end, add the path to your newly installed `file.exe` (typically `C:\Program Files (x86)\GnuWin32\bin`)
6. Restart any CMD shells you have open & see if it works
OR
**Environment**
1. Open `config/environments/development.rb`
2. Add the following line: `Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'`
3. Restart your Rails server
Either of these methods will give your Rails setup access to the `file.exe` functionality, this providing the ability to check the contents of a file (fixing the spoofing problem)
---
Installation
Installation
------------
------------
...
@@ -98,6 +133,8 @@ class ModuleName < ActiveRecord::Base
...
@@ -98,6 +133,8 @@ class ModuleName < ActiveRecord::Base
end
end
```
```
---
Quick Start
Quick Start
-----------
-----------
...
@@ -189,6 +226,7 @@ Set the attribute to `nil` and save.
...
@@ -189,6 +226,7 @@ Set the attribute to `nil` and save.
@user.avatar=nil
@user.avatar=nil
@user.save
@user.save
```
```
---
Usage
Usage
-----
-----
...
@@ -311,6 +349,8 @@ validates_attachment :avatar,
...
@@ -311,6 +349,8 @@ validates_attachment :avatar,
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
inferred content_type, regardless of the actual contents of the file.
inferred content_type, regardless of the actual contents of the file.
Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.
Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.