paperclip 4.3.7 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +13 -9
- data/Appraisals +22 -6
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +2 -8
- data/LICENSE +1 -1
- data/NEWS +39 -27
- data/README.md +123 -101
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +1 -0
- data/features/migration.feature +0 -24
- data/features/step_definitions/rails_steps.rb +0 -6
- data/features/step_definitions/s3_steps.rb +2 -2
- data/gemfiles/{4.1.gemfile → 4.2.awsv2.0.gemfile} +4 -6
- data/gemfiles/4.2.awsv2.1.gemfile +17 -0
- data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -0
- data/gemfiles/5.0.awsv2.0.gemfile +17 -0
- data/gemfiles/5.0.awsv2.1.gemfile +17 -0
- data/gemfiles/{3.2.gemfile → 5.0.awsv2.gemfile} +2 -1
- data/lib/paperclip.rb +2 -3
- data/lib/paperclip/attachment.rb +12 -10
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +14 -10
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +12 -29
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/schema.rb +2 -8
- data/lib/paperclip/storage/fog.rb +9 -6
- data/lib/paperclip/storage/s3.rb +42 -40
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +1 -1
- data/paperclip.gemspec +11 -8
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +33 -10
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +17 -8
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +32 -30
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/paperclip_spec.rb +3 -33
- data/spec/paperclip/storage/fog_spec.rb +10 -0
- data/spec/paperclip/storage/s3_live_spec.rb +8 -4
- data/spec/paperclip/storage/s3_spec.rb +213 -156
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/support/assertions.rb +7 -0
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +44 -37
- data/cucumber/paperclip_steps.rb +0 -6
- data/lib/paperclip/deprecations.rb +0 -42
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/paperclip/deprecations_spec.rb +0 -65
- data/spec/support/deprecations.rb +0 -9
- data/spec/support/rails_helpers.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4787def2cfada09ed3791a17a356d403c289df8a
|
4
|
+
data.tar.gz: fa4e3a08de8f08483299905ea9ed65e9246bcf9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c34f90ee3cce719d4915eab1703bb0825584e2361230402bc705e6d5ac0e98e5cc5dc524380d5bed415c38e208604156223f3315044b76ef98b11ddd8cb1817
|
7
|
+
data.tar.gz: b1b9a56925bb9d9c35725a500f241deab6631c9b1142815dfd1d93104a99de12aa74ae68f4a415599fb3f966ce1b189577e977a1c2d24d521b5f35e592cc76ae
|
data/.travis.yml
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.0
|
3
2
|
- 2.1
|
4
3
|
- 2.2.2
|
5
|
-
- jruby-19mode
|
6
|
-
- rbx-2
|
7
4
|
|
8
5
|
script: "bundle exec rake clean spec cucumber"
|
9
6
|
|
10
7
|
gemfile:
|
11
|
-
- gemfiles/
|
12
|
-
- gemfiles/4.1.gemfile
|
13
|
-
- gemfiles/
|
8
|
+
- gemfiles/4.2.awsv2.0.gemfile
|
9
|
+
- gemfiles/4.2.awsv2.1.gemfile
|
10
|
+
- gemfiles/5.0.awsv2.0.gemfile
|
11
|
+
- gemfiles/5.0.awsv2.1.gemfile
|
14
12
|
|
15
13
|
matrix:
|
16
14
|
fast_finish: true
|
17
|
-
|
18
|
-
-
|
19
|
-
|
15
|
+
exclude:
|
16
|
+
- gemfile: gemfiles/5.0.awsv2.0.gemfile
|
17
|
+
rvm: 2.0
|
18
|
+
- gemfile: gemfiles/5.0.awsv2.1.gemfile
|
19
|
+
rvm: 2.0
|
20
|
+
- gemfile: gemfiles/5.0.awsv2.0.gemfile
|
21
|
+
rvm: 2.1
|
22
|
+
- gemfile: gemfiles/5.0.awsv2.1.gemfile
|
23
|
+
rvm: 2.1
|
20
24
|
|
21
25
|
sudo: false
|
22
26
|
cache: bundler
|
data/Appraisals
CHANGED
@@ -1,11 +1,27 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
1
|
+
appraise "4.2.awsv2.0" do
|
2
|
+
gem "rails", "~> 4.2.0"
|
3
|
+
gem "aws-sdk", "~> 2.0.0"
|
3
4
|
end
|
4
5
|
|
5
|
-
appraise "4.1" do
|
6
|
-
gem "rails", "~> 4.
|
6
|
+
appraise "4.2.awsv2.1" do
|
7
|
+
gem "rails", "~> 4.2.0"
|
8
|
+
gem "aws-sdk", "~> 2.1.0"
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem 'mime-types', '>= 1.16', '< 4'
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
|
-
appraise "
|
10
|
-
gem "rails", "
|
15
|
+
appraise "5.0.awsv2.0" do
|
16
|
+
gem "rails", "5.0.0.beta3"
|
17
|
+
gem "aws-sdk", "~> 2.0.0"
|
18
|
+
|
19
|
+
group :development, :test do
|
20
|
+
gem 'mime-types', '>= 1.16', '< 4'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
appraise "5.0.awsv2.1" do
|
25
|
+
gem "rails", "5.0.0.beta3"
|
26
|
+
gem "aws-sdk", "~> 2.1.0"
|
11
27
|
end
|
data/CONTRIBUTING.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
Contributing
|
2
2
|
============
|
3
3
|
|
4
|
-
We love pull requests.
|
4
|
+
We love pull requests from everyone. By participating in this project, you agree
|
5
|
+
to abide by the thoughtbot [code of conduct].
|
6
|
+
|
7
|
+
[code of conduct]: https://thoughtbot.com/open-source-code-of-conduct
|
8
|
+
|
9
|
+
Here's a quick guide for contributing:
|
5
10
|
|
6
11
|
1. Fork the repo.
|
7
12
|
|
8
|
-
|
13
|
+
1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
|
14
|
+
(./README.md#image-processor) of the README.
|
15
|
+
|
16
|
+
1. Run the tests. We only take pull requests with passing tests, and it's great
|
9
17
|
to know that you have a clean slate: `bundle && bundle exec rake`
|
10
18
|
|
11
|
-
|
19
|
+
1. Add a test for your change. Only refactoring and documentation changes
|
12
20
|
require no new tests. If you are adding functionality or fixing a bug, we need
|
13
21
|
a test!
|
14
22
|
|
15
|
-
|
23
|
+
1. Make the test pass.
|
24
|
+
|
25
|
+
1. Mention how your changes affect the project to other developers and users in
|
26
|
+
the `NEWS.md` file.
|
16
27
|
|
17
|
-
|
28
|
+
1. Push to your fork and submit a pull request.
|
18
29
|
|
19
30
|
At this point you're waiting on us. We like to at least comment on, if not
|
20
31
|
accept, pull requests within seven business days (most of the work on Paperclip
|
data/Gemfile
CHANGED
@@ -3,19 +3,13 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
gem 'sqlite3', '~> 1.3.8', :platforms => :ruby
|
6
|
-
|
7
|
-
gem 'jruby-openssl', :platforms => :jruby
|
8
|
-
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
9
|
-
|
10
|
-
gem 'rubysl', :platforms => :rbx
|
11
|
-
gem 'racc', :platforms => :rbx
|
12
|
-
|
13
6
|
gem 'pry'
|
14
7
|
|
15
8
|
# Hinting at development dependencies
|
16
9
|
# Prevents bundler from taking a long-time to resolve
|
17
10
|
group :development, :test do
|
18
|
-
gem '
|
11
|
+
gem 'activerecord-import'
|
12
|
+
gem 'mime-types'
|
19
13
|
gem 'builder'
|
20
14
|
gem 'rubocop', require: false
|
21
15
|
end
|
data/LICENSE
CHANGED
@@ -3,7 +3,7 @@ LICENSE
|
|
3
3
|
|
4
4
|
The MIT License
|
5
5
|
|
6
|
-
Copyright (c) 2008-
|
6
|
+
Copyright (c) 2008-2016 Jon Yurek and thoughtbot, inc.
|
7
7
|
|
8
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
9
|
of this software and associated documentation files (the "Software"), to deal
|
data/NEWS
CHANGED
@@ -1,39 +1,51 @@
|
|
1
|
-
|
1
|
+
master:
|
2
2
|
|
3
|
-
|
4
|
-
* Improvement: Add `fog_options` configuration to send options to fog when storing files.
|
5
|
-
* Improvement: the `URI adapter` now uses the content-disposition header to name the downloaded file.
|
3
|
+
5.0.0 (2016-07-01):
|
6
4
|
|
7
|
-
|
5
|
+
* Improvement: Add `read_timeout` configuration for URI Adapter download_content method.
|
6
|
+
* README adjustments for Ruby beginners (add links, elucidate model in Quick Start)
|
7
|
+
* Bugfix: Now it's possible to save images from URLs with special characters [#1932]
|
8
|
+
* Bugfix: Return false when file to copy is not present in cloud storage [#2173]
|
9
|
+
* Automatically close file while checking mime type [#2016]
|
10
|
+
* Add `read_timeout` option to `UriAdapter#download_content` method [#2232]
|
11
|
+
* Fix a nil error in content type validation matcher [#1910]
|
12
|
+
* Documentation improvements
|
8
13
|
|
9
|
-
|
14
|
+
5.0.0.beta2 (2016-04-01):
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
*
|
14
|
-
|
15
|
-
4.3.4 (2/2/2016):
|
16
|
-
|
17
|
-
* Bug Fix: Fix incompatible change from v4.3.3.
|
18
|
-
|
19
|
-
4.3.3 (1/29/2016):
|
16
|
+
* Bugfix: Dynamic fog directory option is now respected
|
17
|
+
* Bugfix: Fixes cocaine duplicated paths [#2169]
|
18
|
+
* Removal of dead code (older versions of Rails and AWS SDK)
|
19
|
+
* README adjustments
|
20
20
|
|
21
|
-
|
21
|
+
5.0.0.beta1 (2016-03-13):
|
22
22
|
|
23
|
-
|
23
|
+
* Bug Fix: megabytes of mime-types info in logs when a spoofed media type is detected.
|
24
|
+
* Drop support to end-of-life'd ruby 2.0.
|
25
|
+
* Drop support for end-of-life'd Rails 3.2 and 4.1
|
26
|
+
* Drop support for AWS v1
|
27
|
+
* Remove tests for JRuby and Rubinius from Travis CI (they were failing)
|
28
|
+
* Improvement: Add `fog_options` configuration to send options to fog when
|
29
|
+
storing files.
|
30
|
+
* Extracted repository for locales only: https://github.com/thoughtbot/paperclip-i18n
|
31
|
+
* Bugfix: Original file could be unlinked during `post_process_style`, producing failures
|
32
|
+
* Bugfix for image magick scaling images up
|
33
|
+
* Memory consumption improvements
|
34
|
+
* `url` on a unpersisted record returns `default_url` rather than `nil`
|
35
|
+
* Improvement: aws-sdk v2 support
|
36
|
+
https://github.com/thoughtbot/paperclip/pull/1903
|
24
37
|
|
25
|
-
|
38
|
+
If your Gemfile contains aws-sdk (>= 2.0.0) and aws-sdk-v1, paperclip will use
|
39
|
+
aws-sdk v2. With aws-sdk v2, S3 storage requires you to set the s3_region.
|
40
|
+
s3_region may be nested in s3_credentials, and (if not nested in
|
41
|
+
s3_credentials) it may be a Proc.
|
26
42
|
|
27
|
-
4.3
|
43
|
+
4.3
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
* Fix GeometryParser regex for usage of '@>' flag
|
32
|
-
* `url` on a unpersisted record returns default_url
|
33
|
-
* spec deprecation warnings and failures
|
34
|
-
* README adjustments
|
45
|
+
See patch versions in v4.3 NEWS:
|
46
|
+
https://github.com/thoughtbot/paperclip/blob/v4.3/NEWS
|
35
47
|
|
36
|
-
4.3.0 (
|
48
|
+
4.3.0 (2015-06-18):
|
37
49
|
|
38
50
|
* Improvement: Update aws-sdk and cucumber gem versions.
|
39
51
|
* Improvement: Add `length` alias for `size` method in AbstractAdapter.
|
@@ -46,7 +58,7 @@
|
|
46
58
|
* Ruby Versioning: Drop support for 1.9.3 (EOL'ed)
|
47
59
|
* Rails Versioning: Drop support for 4.0.0 (EOL'ed)
|
48
60
|
|
49
|
-
4.2.4:
|
61
|
+
4.2.4 (2015-06-05):
|
50
62
|
|
51
63
|
* Rollback backwards incompatible change, allowing paperclip to run on
|
52
64
|
Ruby >= 1.9.2.
|
data/README.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
Paperclip
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
4
|
+
## Documentation valid for `master` branch
|
5
|
+
|
6
|
+
Please check the documentation for the paperclip version you are using:
|
7
|
+
https://github.com/thoughtbot/paperclip/releases
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
[![Build Status](https://secure.travis-ci.org/thoughtbot/paperclip.svg?branch=master)](http://travis-ci.org/thoughtbot/paperclip)
|
12
|
+
[![Dependency Status](https://gemnasium.com/thoughtbot/paperclip.svg?travis)](https://gemnasium.com/thoughtbot/paperclip)
|
13
|
+
[![Code Climate](https://codeclimate.com/github/thoughtbot/paperclip.svg)](https://codeclimate.com/github/thoughtbot/paperclip)
|
14
|
+
[![Inline docs](http://inch-ci.org/github/thoughtbot/paperclip.svg)](http://inch-ci.org/github/thoughtbot/paperclip)
|
15
|
+
[![Security](https://hakiri.io/github/thoughtbot/paperclip/master.svg)](https://hakiri.io/github/thoughtbot/paperclip/master)
|
16
|
+
|
17
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
18
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
19
|
+
|
5
20
|
|
6
21
|
- [Requirements](#requirements)
|
7
|
-
- [Ruby
|
22
|
+
- [Ruby and Rails](#ruby-and-rails)
|
8
23
|
- [Image Processor](#image-processor)
|
9
|
-
- [file](#file)
|
24
|
+
- [`file`](#file)
|
10
25
|
- [Installation](#installation)
|
11
26
|
- [Quick Start](#quick-start)
|
12
27
|
- [Models](#models)
|
@@ -14,35 +29,39 @@ Paperclip
|
|
14
29
|
- [Edit and New Views](#edit-and-new-views)
|
15
30
|
- [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
|
16
31
|
- [Controller](#controller)
|
17
|
-
- [
|
32
|
+
- [View Helpers](#view-helpers)
|
18
33
|
- [Deleting an Attachment](#deleting-an-attachment)
|
19
34
|
- [Usage](#usage)
|
20
35
|
- [Validations](#validations)
|
36
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
21
37
|
- [Security Validations](#security-validations)
|
22
38
|
- [Defaults](#defaults)
|
23
39
|
- [Migrations](#migrations-1)
|
24
|
-
- [Table
|
40
|
+
- [Add Attachment Column To A Table](#add-attachment-column-to-a-table)
|
25
41
|
- [Schema Definition](#schema-definition)
|
26
|
-
- [Vintage
|
42
|
+
- [Vintage syntax](#vintage-syntax)
|
27
43
|
- [Storage](#storage)
|
28
44
|
- [Understanding Storage](#understanding-storage)
|
29
45
|
- [Post Processing](#post-processing)
|
30
46
|
- [Events](#events)
|
31
47
|
- [URI Obfuscation](#uri-obfuscation)
|
32
|
-
|
33
|
-
|
48
|
+
- [MD5 Checksum / Fingerprint](#md5-checksum--fingerprint)
|
49
|
+
- [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
|
34
50
|
- [Custom Attachment Processors](#custom-attachment-processors)
|
35
51
|
- [Dynamic Configuration](#dynamic-configuration)
|
36
|
-
- [Dynamic Styles](#dynamic-styles)
|
37
|
-
- [Dynamic Processors](#dynamic-processors)
|
52
|
+
- [Dynamic Styles:](#dynamic-styles)
|
53
|
+
- [Dynamic Processors:](#dynamic-processors)
|
38
54
|
- [Logging](#logging)
|
39
55
|
- [Deployment](#deployment)
|
56
|
+
- [Attachment Styles](#attachment-styles)
|
40
57
|
- [Testing](#testing)
|
41
58
|
- [Contributing](#contributing)
|
42
59
|
- [License](#license)
|
43
60
|
- [About thoughtbot](#about-thoughtbot)
|
44
61
|
|
45
|
-
|
62
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
63
|
+
|
64
|
+
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
46
65
|
intent behind it was to keep setup as easy as possible and to treat files as
|
47
66
|
much like other attributes as possible. This means they aren't saved to their
|
48
67
|
final locations on disk, nor are they deleted if set to nil, until
|
@@ -54,10 +73,10 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
54
73
|
browser by an easily understandable specification, which has sensible and
|
55
74
|
useful defaults.
|
56
75
|
|
57
|
-
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
76
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
58
77
|
more detailed options.
|
59
78
|
|
60
|
-
The complete [RDoc](http://
|
79
|
+
The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
|
61
80
|
|
62
81
|
---
|
63
82
|
|
@@ -66,9 +85,8 @@ Requirements
|
|
66
85
|
|
67
86
|
### Ruby and Rails
|
68
87
|
|
69
|
-
Paperclip now requires Ruby version **>= 2.
|
70
|
-
|
71
|
-
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](http://rubydoc.info/gems/paperclip/2.7.0) instead.
|
88
|
+
Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2**
|
89
|
+
(only if you're going to use Paperclip with Ruby on Rails.)
|
72
90
|
|
73
91
|
### Image Processor
|
74
92
|
|
@@ -86,7 +104,7 @@ In development mode, you might add this line to `config/environments/development
|
|
86
104
|
Paperclip.options[:command_path] = "/usr/local/bin/"
|
87
105
|
```
|
88
106
|
|
89
|
-
If you're on Mac OS X, you'll want to run the following with Homebrew:
|
107
|
+
If you're on Mac OS X, you'll want to run the following with [Homebrew] (http://www.brew.sh):
|
90
108
|
|
91
109
|
brew install imagemagick
|
92
110
|
|
@@ -95,17 +113,14 @@ to install GhostScript. On Mac OS X, you can also install that using Homebrew:
|
|
95
113
|
|
96
114
|
brew install gs
|
97
115
|
|
98
|
-
If you
|
99
|
-
|
100
|
-
sudo apt-get install imagemagick -y
|
101
|
-
|
102
|
-
If you're on Ubuntu (or any Debian base Linux distribution), you'll want to run the following with apt-get:
|
116
|
+
If you are on Ubuntu (or any Debian base Linux distribution), you'll want to run
|
117
|
+
the following with apt-get:
|
103
118
|
|
104
119
|
sudo apt-get install imagemagick -y
|
105
120
|
|
106
121
|
### `file`
|
107
122
|
|
108
|
-
The Unix [`file` command](
|
123
|
+
The Unix [`file` command](https://en.wikipedia.org/wiki/File_(command)) is required for content-type checking.
|
109
124
|
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
|
110
125
|
so Windows users must make sure that the devkit is installed and added to the system `PATH`.
|
111
126
|
|
@@ -151,18 +166,18 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
151
166
|
Include the gem in your Gemfile:
|
152
167
|
|
153
168
|
```ruby
|
154
|
-
gem "paperclip", "~>
|
169
|
+
gem "paperclip", "~> 5.0.0"
|
155
170
|
```
|
156
171
|
|
157
172
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
158
173
|
|
159
174
|
```ruby
|
160
|
-
gem "paperclip", :
|
175
|
+
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
|
161
176
|
```
|
162
177
|
|
163
178
|
If you're trying to use features that don't seem to be in the latest released gem, but are
|
164
179
|
mentioned in this README, then you probably need to specify the master branch if you want to
|
165
|
-
use them. This README is probably ahead of the latest released version
|
180
|
+
use them. This README is probably ahead of the latest released version if you're reading it
|
166
181
|
on GitHub.
|
167
182
|
|
168
183
|
For Non-Rails usage:
|
@@ -181,22 +196,10 @@ Quick Start
|
|
181
196
|
|
182
197
|
### Models
|
183
198
|
|
184
|
-
**Rails 3**
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
class User < ActiveRecord::Base
|
188
|
-
attr_accessible :avatar
|
189
|
-
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
|
190
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
191
|
-
end
|
192
|
-
```
|
193
|
-
|
194
|
-
**Rails 4**
|
195
|
-
|
196
199
|
```ruby
|
197
200
|
class User < ActiveRecord::Base
|
198
|
-
has_attached_file :avatar, :
|
199
|
-
validates_attachment_content_type :avatar, :
|
201
|
+
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
|
202
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
200
203
|
end
|
201
204
|
```
|
202
205
|
|
@@ -219,12 +222,13 @@ end
|
|
219
222
|
### Edit and New Views
|
220
223
|
|
221
224
|
```erb
|
222
|
-
<%= form_for @user, :
|
225
|
+
<%= form_for @user, url: users_path, html: { multipart: true } do |form| %>
|
223
226
|
<%= form.file_field :avatar %>
|
224
227
|
<% end %>
|
225
228
|
```
|
226
229
|
|
227
|
-
### Edit and New Views with Simple Form
|
230
|
+
### Edit and New Views with [Simple Form](https://github.com/plataformatec/simple_form)
|
231
|
+
|
228
232
|
```erb
|
229
233
|
<%= simple_form_for @user, url: users_path do |form| %>
|
230
234
|
<%= form.input :avatar, as: :file %>
|
@@ -233,16 +237,6 @@ end
|
|
233
237
|
|
234
238
|
### Controller
|
235
239
|
|
236
|
-
**Rails 3**
|
237
|
-
|
238
|
-
```ruby
|
239
|
-
def create
|
240
|
-
@user = User.create( params[:user] )
|
241
|
-
end
|
242
|
-
```
|
243
|
-
|
244
|
-
**Rails 4**
|
245
|
-
|
246
240
|
```ruby
|
247
241
|
def create
|
248
242
|
@user = User.create( user_params )
|
@@ -258,7 +252,7 @@ def user_params
|
|
258
252
|
end
|
259
253
|
```
|
260
254
|
|
261
|
-
###
|
255
|
+
### View Helpers
|
262
256
|
|
263
257
|
```erb
|
264
258
|
<%= image_tag @user.avatar.url %>
|
@@ -296,7 +290,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
|
|
296
290
|
validation.
|
297
291
|
|
298
292
|
More information about the options passed to `has_attached_file` is available in the
|
299
|
-
documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
293
|
+
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
300
294
|
|
301
295
|
Validations
|
302
296
|
-----------
|
@@ -310,9 +304,9 @@ For validations, Paperclip introduces several validators to validate your attach
|
|
310
304
|
Example Usage:
|
311
305
|
|
312
306
|
```ruby
|
313
|
-
validates :avatar, :
|
314
|
-
validates_with AttachmentPresenceValidator, :
|
315
|
-
validates_with AttachmentSizeValidator, :
|
307
|
+
validates :avatar, attachment_presence: true
|
308
|
+
validates_with AttachmentPresenceValidator, attributes: :avatar
|
309
|
+
validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 1.megabytes
|
316
310
|
|
317
311
|
```
|
318
312
|
|
@@ -331,9 +325,9 @@ validates_attachment_presence :avatar
|
|
331
325
|
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
|
332
326
|
|
333
327
|
```ruby
|
334
|
-
validates_attachment :avatar, :
|
335
|
-
:
|
336
|
-
:
|
328
|
+
validates_attachment :avatar, presence: true,
|
329
|
+
content_type: { content_type: "image/jpeg" },
|
330
|
+
size: { in: 0..10.kilobytes }
|
337
331
|
```
|
338
332
|
|
339
333
|
_NOTE: Post-processing will not even **start** if the attachment is not valid
|
@@ -391,7 +385,7 @@ image-y ones:
|
|
391
385
|
|
392
386
|
```ruby
|
393
387
|
validates_attachment :avatar,
|
394
|
-
:
|
388
|
+
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
395
389
|
```
|
396
390
|
|
397
391
|
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
|
@@ -399,6 +393,12 @@ inferred content_type, regardless of the actual contents of the file.
|
|
399
393
|
|
400
394
|
---
|
401
395
|
|
396
|
+
Internationalization (I18n)
|
397
|
+
---------------------------
|
398
|
+
|
399
|
+
For using or adding locale files in different languages, check the project
|
400
|
+
https://github.com/thoughtbot/paperclip-i18n.
|
401
|
+
|
402
402
|
Security Validations
|
403
403
|
====================
|
404
404
|
|
@@ -415,9 +415,9 @@ do this.
|
|
415
415
|
class ActiveRecord::Base
|
416
416
|
has_attached_file :avatar
|
417
417
|
# Validate content type
|
418
|
-
validates_attachment_content_type :avatar, :
|
418
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage/
|
419
419
|
# Validate filename
|
420
|
-
validates_attachment_file_name :avatar, :
|
420
|
+
validates_attachment_file_name :avatar, matches: [/png\Z/, /jpe?g\Z/]
|
421
421
|
# Explicitly do not validate
|
422
422
|
do_not_validate_attachment_file_type :avatar
|
423
423
|
end
|
@@ -437,14 +437,13 @@ will not cause errors to be raised.
|
|
437
437
|
|
438
438
|
This can sometimes cause false validation errors in applications that use custom
|
439
439
|
file extensions. In these cases you may wish to add your custom extension to the
|
440
|
-
list of
|
441
|
-
gem:
|
440
|
+
list of content type mappings by creating `config/initializers/paperclip.rb`:
|
442
441
|
|
443
442
|
```ruby
|
444
443
|
# Allow ".foo" as an extension for files with the MIME type "text/plain".
|
445
|
-
|
446
|
-
|
447
|
-
|
444
|
+
Paperclip.options[:content_type_mappings] = {
|
445
|
+
foo: %w(text/plain)
|
446
|
+
}
|
448
447
|
```
|
449
448
|
|
450
449
|
---
|
@@ -460,7 +459,7 @@ module YourApp
|
|
460
459
|
class Application < Rails::Application
|
461
460
|
# Other code...
|
462
461
|
|
463
|
-
config.paperclip_defaults = {:
|
462
|
+
config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
|
464
463
|
end
|
465
464
|
end
|
466
465
|
```
|
@@ -471,7 +470,7 @@ An example Rails initializer would look something like this:
|
|
471
470
|
|
472
471
|
```ruby
|
473
472
|
Paperclip::Attachment.default_options[:storage] = :fog
|
474
|
-
Paperclip::Attachment.default_options[:fog_credentials] = {:
|
473
|
+
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
|
475
474
|
Paperclip::Attachment.default_options[:fog_directory] = ""
|
476
475
|
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
|
477
476
|
```
|
@@ -493,6 +492,7 @@ class CreateUsersWithAttachments < ActiveRecord::Migration
|
|
493
492
|
create_table :users do |t|
|
494
493
|
t.attachment :avatar
|
495
494
|
end
|
495
|
+
end
|
496
496
|
|
497
497
|
# This is assuming you are only using the users table for Paperclip attachment. Drop with care!
|
498
498
|
def down
|
@@ -566,9 +566,9 @@ gems along side with Paperclip:
|
|
566
566
|
The files that are assigned as attachments are, by default, placed in the
|
567
567
|
directory specified by the `:path` option to `has_attached_file`. By default, this
|
568
568
|
location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
|
569
|
-
This location was chosen because on standard Capistrano deployments, the
|
570
|
-
`public/system` directory
|
571
|
-
|
569
|
+
This location was chosen because, on standard Capistrano deployments, the
|
570
|
+
`public/system` directory can be symlinked to the app's shared directory, meaning it
|
571
|
+
survives between deployments. For example, using that `:path`, you may have a
|
572
572
|
file at
|
573
573
|
|
574
574
|
/data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png
|
@@ -580,12 +580,12 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
|
|
580
580
|
the `aws-sdk` gem in your Gemfile:
|
581
581
|
|
582
582
|
```ruby
|
583
|
-
gem 'aws-sdk', '
|
583
|
+
gem 'aws-sdk', '>= 2.0.34'
|
584
584
|
```
|
585
585
|
|
586
586
|
And then you can specify using S3 from `has_attached_file`.
|
587
587
|
You can find more information about configuring and using S3 storage in
|
588
|
-
[the `Paperclip::Storage::S3` documentation](http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
588
|
+
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
589
589
|
|
590
590
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
591
591
|
available to the internet at large. If you require access control, it's
|
@@ -610,20 +610,21 @@ processors. You can specify a processor with the `:processors` option to
|
|
610
610
|
`has_attached_file`:
|
611
611
|
|
612
612
|
```ruby
|
613
|
-
has_attached_file :scan, :
|
614
|
-
:
|
613
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
614
|
+
processors: [:ocr]
|
615
615
|
```
|
616
616
|
|
617
617
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
618
|
-
hash "{ :
|
619
|
-
more information about defining processors, see
|
618
|
+
hash "{ quality: :better }" passed to it along with the uploaded file. For
|
619
|
+
more information about defining processors, see
|
620
|
+
[Paperclip::Processor](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb).
|
620
621
|
|
621
|
-
The default processor is Paperclip::Thumbnail. For
|
622
|
+
The default processor is Paperclip::Thumbnail. For backward compatibility
|
622
623
|
reasons, you can pass a single geometry string or an array containing a
|
623
624
|
geometry and a format that the file will be converted to, like so:
|
624
625
|
|
625
626
|
```ruby
|
626
|
-
has_attached_file :avatar, :
|
627
|
+
has_attached_file :avatar, styles: { thumb: ["32x32#", :png] }
|
627
628
|
```
|
628
629
|
|
629
630
|
This will convert the "thumb" style to a 32x32 square in PNG format, regardless
|
@@ -638,12 +639,12 @@ receive the same parameters, which are defined in the `:styles` hash.
|
|
638
639
|
For example, assuming we had this definition:
|
639
640
|
|
640
641
|
```ruby
|
641
|
-
has_attached_file :scan, :
|
642
|
-
:
|
642
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
643
|
+
processors: [:rotator, :ocr]
|
643
644
|
```
|
644
645
|
|
645
646
|
then both the :rotator processor and the :ocr processor would receive the
|
646
|
-
options `{ :
|
647
|
+
options `{ quality: :better }`. This parameter may not mean anything to one
|
647
648
|
or more or the processors, and they are expected to ignore it.
|
648
649
|
|
649
650
|
_NOTE: Because processors operate by turning the original attachment into the
|
@@ -699,8 +700,8 @@ Example Usage:
|
|
699
700
|
|
700
701
|
```ruby
|
701
702
|
has_attached_file :avatar, {
|
702
|
-
:
|
703
|
-
:
|
703
|
+
url: "/system/:hash.:extension",
|
704
|
+
hash_secret: "longSecretString"
|
704
705
|
}
|
705
706
|
```
|
706
707
|
|
@@ -738,7 +739,7 @@ An option is available to preserve attachments in order to play nicely with soft
|
|
738
739
|
|
739
740
|
```ruby
|
740
741
|
has_attached_file :some_attachment, {
|
741
|
-
:
|
742
|
+
preserve_files: "true",
|
742
743
|
}
|
743
744
|
```
|
744
745
|
|
@@ -786,7 +787,7 @@ look as follows where a boss will receive a `300x300` thumbnail otherwise a
|
|
786
787
|
|
787
788
|
```ruby
|
788
789
|
class User < ActiveRecord::Base
|
789
|
-
has_attached_file :avatar, :
|
790
|
+
has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } }
|
790
791
|
end
|
791
792
|
```
|
792
793
|
|
@@ -803,7 +804,7 @@ processors, where a defined `watermark` processor is invoked after the
|
|
803
804
|
|
804
805
|
```ruby
|
805
806
|
class User < ActiveRecord::Base
|
806
|
-
has_attached_file :avatar, :
|
807
|
+
has_attached_file :avatar, processors: lambda { |instance| instance.processors }
|
807
808
|
attr_accessor :processors
|
808
809
|
end
|
809
810
|
```
|
@@ -813,7 +814,7 @@ end
|
|
813
814
|
Logging
|
814
815
|
----------
|
815
816
|
|
816
|
-
By default Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this
|
817
|
+
By default, Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this into your environment's configuration:
|
817
818
|
```ruby
|
818
819
|
Your::Application.configure do
|
819
820
|
...
|
@@ -822,13 +823,23 @@ Your::Application.configure do
|
|
822
823
|
end
|
823
824
|
```
|
824
825
|
|
825
|
-
More information in the [rdocs](http://
|
826
|
+
More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip.options)
|
826
827
|
|
827
828
|
---
|
828
829
|
|
829
830
|
Deployment
|
830
831
|
----------
|
831
832
|
|
833
|
+
To make Capistrano symlink the `public/system` directory so that attachments
|
834
|
+
survive new deployments, set the `linked_dirs` option in your `config/deploy.rb`
|
835
|
+
file:
|
836
|
+
|
837
|
+
```ruby
|
838
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
|
839
|
+
```
|
840
|
+
|
841
|
+
### Attachment Styles
|
842
|
+
|
832
843
|
Paperclip is aware of new attachment styles you have added in previous deploys. The only thing you should do after each deployment is to call
|
833
844
|
`rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
|
834
845
|
by default. You can change it by:
|
@@ -840,9 +851,9 @@ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachment
|
|
840
851
|
Here is an example for Capistrano:
|
841
852
|
|
842
853
|
```ruby
|
843
|
-
namespace :
|
854
|
+
namespace :paperclip do
|
844
855
|
desc "build missing paperclip styles"
|
845
|
-
task :
|
856
|
+
task :build_missing_styles do
|
846
857
|
on roles(:app) do
|
847
858
|
within release_path do
|
848
859
|
with rails_env: fetch(:rails_env) do
|
@@ -853,7 +864,7 @@ namespace :deploy do
|
|
853
864
|
end
|
854
865
|
end
|
855
866
|
|
856
|
-
after("deploy:compile_assets", "
|
867
|
+
after("deploy:compile_assets", "paperclip:build_missing_styles")
|
857
868
|
```
|
858
869
|
|
859
870
|
Now you don't have to remember to refresh thumbnails in production every time you add a new style.
|
@@ -864,12 +875,12 @@ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` fil
|
|
864
875
|
|
865
876
|
```ruby
|
866
877
|
class User < ActiveRecord::Base
|
867
|
-
has_attached_file :avatar, :
|
878
|
+
has_attached_file :avatar, styles: { thumb: 'x100', croppable: '600x600>', big: '1000x1000>' }
|
868
879
|
end
|
869
880
|
|
870
881
|
class Book < ActiveRecord::Base
|
871
|
-
has_attached_file :cover, :
|
872
|
-
has_attached_file :sample, :
|
882
|
+
has_attached_file :cover, styles: { small: 'x100', large: '1000x1000>' }
|
883
|
+
has_attached_file :sample, styles: { thumb: 'x100' }
|
873
884
|
end
|
874
885
|
```
|
875
886
|
|
@@ -896,7 +907,7 @@ Testing
|
|
896
907
|
-------
|
897
908
|
|
898
909
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
899
|
-
documentation on [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
910
|
+
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
900
911
|
for more information.
|
901
912
|
|
902
913
|
**Parallel Tests**
|
@@ -936,6 +947,17 @@ config.after(:suite) do
|
|
936
947
|
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
937
948
|
end
|
938
949
|
```
|
950
|
+
|
951
|
+
**Example of test configuration with Factory Girl**
|
952
|
+
|
953
|
+
|
954
|
+
```ruby
|
955
|
+
FactoryGirl.define do
|
956
|
+
factory :user do
|
957
|
+
avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
|
958
|
+
end
|
959
|
+
end
|
960
|
+
```
|
939
961
|
---
|
940
962
|
|
941
963
|
Contributing
|
@@ -951,14 +973,14 @@ guidelines:
|
|
951
973
|
about writing tests for paperclip, please open a
|
952
974
|
[GitHub issue](https://github.com/thoughtbot/paperclip/issues/new).
|
953
975
|
|
954
|
-
Please see `CONTRIBUTING.md` for more details on contributing and running test.
|
976
|
+
Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
|
955
977
|
|
956
|
-
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
|
978
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
|
957
979
|
|
958
980
|
License
|
959
981
|
-------
|
960
982
|
|
961
|
-
Paperclip is Copyright © 2008-
|
983
|
+
Paperclip is Copyright © 2008-2016 thoughtbot, inc. It is free software, and may be
|
962
984
|
redistributed under the terms specified in the MIT-LICENSE file.
|
963
985
|
|
964
986
|
About thoughtbot
|