- Requirements
- Installation
- Quick Start
- Usage
- Validations
- Security Validations
- Defaults
- Migrations
- Storage
- Post Processing
- Events
- URI Obfuscation
- Custom Attachment Processors
- Dynamic Configuration
- Logging
- Deployment
- Testing
- Contributing
- License
- About thoughtbot
Paperclip is intended as an easy file attachment library for Active Record. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their final locations on disk, nor are they deleted if set to nil, until ActiveRecord::Base#save is called. It manages validations based on size and presence, if required. It can transform its assigned image into thumbnails if needed, and the prerequisites are as simple as installing ImageMagick (which, for most modern Unix-based systems, is as easy as installing the right packages). Attached files are saved to the filesystem and referenced in the browser by an easily understandable specification, which has sensible and useful defaults.
See the documentation for has_attached_file
in Paperclip::ClassMethods
for
more detailed options.
The complete RDoc is online.
Paperclip now requires Ruby version >= 2.0.0 and Rails version 3.2, >= 4.1 (Only if you're going to use Paperclip with Ruby on Rails.)
If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still use Paperclip 2.7.x with your project. Also, everything in this README might not apply to your version of Paperclip, and you should read the README for version 2.7 instead.
ImageMagick must be installed and Paperclip must have access to it. To ensure
that it does, on your command line, run which convert
(one of the ImageMagick
utilities). This will give you the path where that utility is installed. For
example, it might return /usr/local/bin/convert
.
Then, in your environment config file, let Paperclip know to look there by adding that directory to its path.
In development mode, you might add this line to config/environments/development.rb)
:
Paperclip.options[:command_path] = "/usr/local/bin/"
If you're on Mac OS X, you'll want to run the following with Homebrew:
brew install imagemagick
If you are dealing with pdf uploads or running the test suite, you'll also need to install GhostScript. On Mac OS X, you can also install that using Homebrew:
brew install gs
The Unix file
command is required for content-type checking.
This utility isn't available in Windows, but comes bundled with Ruby Devkit,
so Windows users must make sure that the devkit is installed and added to the 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
To test, you can use the image below:
Next, you need to integrate with your environment - preferably 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, thus providing the ability to check the contents of a file (fixing the spoofing problem)
Paperclip is distributed as a gem, which is how it should be used in your app.
Include the gem in your Gemfile:
< 67E6 div class="highlight highlight-source-ruby notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="gem "paperclip", "~> 4.3"">gem "paperclip", "~> 4.3"