paperclip 4.3.7 → 5.0.0.beta1
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 +6 -1
- data/Gemfile +2 -8
- data/LICENSE +1 -1
- data/NEWS +28 -37
- data/README.md +81 -63
- data/UPGRADING +9 -9
- data/features/basic_integration.feature +1 -0
- data/features/step_definitions/s3_steps.rb +6 -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} +7 -1
- data/lib/paperclip.rb +0 -2
- data/lib/paperclip/attachment.rb +9 -8
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +11 -30
- data/lib/paperclip/schema.rb +1 -2
- data/lib/paperclip/storage/s3.rb +59 -35
- data/lib/paperclip/version.rb +1 -1
- data/paperclip.gemspec +11 -7
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +32 -6
- 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 +5 -8
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +6 -31
- data/spec/paperclip/media_type_spoof_detector_spec.rb +3 -12
- data/spec/paperclip/paperclip_spec.rb +0 -32
- data/spec/paperclip/storage/s3_live_spec.rb +8 -4
- data/spec/paperclip/storage/s3_spec.rb +345 -165
- data/spec/paperclip/validators_spec.rb +2 -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 +45 -40
- 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: a699912c4b56d87a1b16846ed1b9772f6149aeeb
|
4
|
+
data.tar.gz: f975845257fa910032dfc7b52913cd2b17917079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c3a1935badc5820ca134933317f37bd284b2d01ff755b52250f5105e27aa562e3bfb9d20f1aa95c44994b0de477c1feec81d24b53be3e5e9e1852bd45d5448
|
7
|
+
data.tar.gz: 43b0e540a847140ba445040281be26d23308f9afe204d0bd5911fa6b245cd7cbb079e987460effe2784d94f7019313cbb5fd662fe9c1dc09160bcde9cb28db13
|
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,7 +1,12 @@
|
|
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
|
|
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,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
*
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
4.3.
|
28
|
-
|
29
|
-
* Backport of bugfix to `remove_column`, so it works in Rails 3 and 4
|
30
|
-
c740fb171fe2f88c60b999d2a1c2122f2b8f43e9
|
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
|
35
|
-
|
36
|
-
4.3.0 (6/18/2015):
|
1
|
+
5.0.0.beta1
|
2
|
+
|
3
|
+
* Drop support to end-of-life'd ruby 2.0.
|
4
|
+
* Drop support for end-of-life'd Rails 3.2 and 4.1
|
5
|
+
* Drop support for AWS v1
|
6
|
+
* Remove tests for JRuby and Rubinius from Travis CI (they were failing)
|
7
|
+
* Improvement: Add `fog_options` configuration to send options to fog when
|
8
|
+
storing files.
|
9
|
+
* Extracted repository for locales only: https://github.com/thoughtbot/paperclip-i18n
|
10
|
+
* Bugfix: Original file could be unlinked during `post_process_style`, producing failures
|
11
|
+
* Bugfix for image magick scaling images up
|
12
|
+
* Memory consumption improvements
|
13
|
+
* `url` on a unpersisted record returns `default_url` rather than `nil`
|
14
|
+
* Improvement: aws-sdk v2 support
|
15
|
+
https://github.com/thoughtbot/paperclip/pull/1903
|
16
|
+
|
17
|
+
If your Gemfile contains aws-sdk (>= 2.0.0) and aws-sdk-v1, paperclip will use
|
18
|
+
aws-sdk v2. With aws-sdk v2, S3 storage requires you to set the s3_region.
|
19
|
+
s3_region may be nested in s3_credentials, and (if not nested in
|
20
|
+
s3_credentials) it may be a Proc.
|
21
|
+
|
22
|
+
4.3
|
23
|
+
|
24
|
+
See patch versions in v4.3 NEWS:
|
25
|
+
https://github.com/thoughtbot/paperclip/blob/v4.3/NEWS
|
26
|
+
|
27
|
+
4.3.0 (2015-06-18):
|
37
28
|
|
38
29
|
* Improvement: Update aws-sdk and cucumber gem versions.
|
39
30
|
* Improvement: Add `length` alias for `size` method in AbstractAdapter.
|
@@ -46,7 +37,7 @@
|
|
46
37
|
* Ruby Versioning: Drop support for 1.9.3 (EOL'ed)
|
47
38
|
* Rails Versioning: Drop support for 4.0.0 (EOL'ed)
|
48
39
|
|
49
|
-
4.2.4:
|
40
|
+
4.2.4 (2015-06-05):
|
50
41
|
|
51
42
|
* Rollback backwards incompatible change, allowing paperclip to run on
|
52
43
|
Ruby >= 1.9.2.
|
data/README.md
CHANGED
@@ -1,12 +1,23 @@
|
|
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)
|
5
16
|
|
6
17
|
- [Requirements](#requirements)
|
7
|
-
- [Ruby
|
18
|
+
- [Ruby and Rails](#ruby-and-rails)
|
8
19
|
- [Image Processor](#image-processor)
|
9
|
-
- [file](#file)
|
20
|
+
- [`file`](#file)
|
10
21
|
- [Installation](#installation)
|
11
22
|
- [Quick Start](#quick-start)
|
12
23
|
- [Models](#models)
|
@@ -18,19 +29,20 @@ Paperclip
|
|
18
29
|
- [Deleting an Attachment](#deleting-an-attachment)
|
19
30
|
- [Usage](#usage)
|
20
31
|
- [Validations](#validations)
|
32
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
21
33
|
- [Security Validations](#security-validations)
|
22
34
|
- [Defaults](#defaults)
|
23
35
|
- [Migrations](#migrations-1)
|
24
|
-
- [Table
|
36
|
+
- [Add Attachment Column To A Table](#add-attachment-column-to-a-table)
|
25
37
|
- [Schema Definition](#schema-definition)
|
26
|
-
- [Vintage
|
38
|
+
- [Vintage syntax](#vintage-syntax)
|
27
39
|
- [Storage](#storage)
|
28
40
|
- [Understanding Storage](#understanding-storage)
|
29
41
|
- [Post Processing](#post-processing)
|
30
42
|
- [Events](#events)
|
31
43
|
- [URI Obfuscation](#uri-obfuscation)
|
32
|
-
|
33
|
-
|
44
|
+
- [MD5 Checksum / Fingerprint](#md5-checksum--fingerprint)
|
45
|
+
- [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
|
34
46
|
- [Custom Attachment Processors](#custom-attachment-processors)
|
35
47
|
- [Dynamic Configuration](#dynamic-configuration)
|
36
48
|
- [Dynamic Styles](#dynamic-styles)
|
@@ -42,7 +54,7 @@ Paperclip
|
|
42
54
|
- [License](#license)
|
43
55
|
- [About thoughtbot](#about-thoughtbot)
|
44
56
|
|
45
|
-
Paperclip is intended as an easy file attachment library for
|
57
|
+
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
46
58
|
intent behind it was to keep setup as easy as possible and to treat files as
|
47
59
|
much like other attributes as possible. This means they aren't saved to their
|
48
60
|
final locations on disk, nor are they deleted if set to nil, until
|
@@ -54,10 +66,10 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
54
66
|
browser by an easily understandable specification, which has sensible and
|
55
67
|
useful defaults.
|
56
68
|
|
57
|
-
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
69
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
58
70
|
more detailed options.
|
59
71
|
|
60
|
-
The complete [RDoc](http://
|
72
|
+
The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
|
61
73
|
|
62
74
|
---
|
63
75
|
|
@@ -66,9 +78,8 @@ Requirements
|
|
66
78
|
|
67
79
|
### Ruby and Rails
|
68
80
|
|
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.
|
81
|
+
Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2**
|
82
|
+
(only if you're going to use Paperclip with Ruby on Rails.)
|
72
83
|
|
73
84
|
### Image Processor
|
74
85
|
|
@@ -95,17 +106,14 @@ to install GhostScript. On Mac OS X, you can also install that using Homebrew:
|
|
95
106
|
|
96
107
|
brew install gs
|
97
108
|
|
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:
|
109
|
+
If you are on Ubuntu (or any Debian base Linux distribution), you'll want to run
|
110
|
+
the following with apt-get:
|
103
111
|
|
104
112
|
sudo apt-get install imagemagick -y
|
105
113
|
|
106
114
|
### `file`
|
107
115
|
|
108
|
-
The Unix [`file` command](
|
116
|
+
The Unix [`file` command](https://en.wikipedia.org/wiki/File_(command)) is required for content-type checking.
|
109
117
|
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
|
110
118
|
so Windows users must make sure that the devkit is installed and added to the system `PATH`.
|
111
119
|
|
@@ -151,18 +159,18 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
151
159
|
Include the gem in your Gemfile:
|
152
160
|
|
153
161
|
```ruby
|
154
|
-
gem "paperclip", "~>
|
162
|
+
gem "paperclip", "~> 5.0"
|
155
163
|
```
|
156
164
|
|
157
165
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
158
166
|
|
159
167
|
```ruby
|
160
|
-
gem "paperclip", :
|
168
|
+
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
|
161
169
|
```
|
162
170
|
|
163
171
|
If you're trying to use features that don't seem to be in the latest released gem, but are
|
164
172
|
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
|
173
|
+
use them. This README is probably ahead of the latest released version if you're reading it
|
166
174
|
on GitHub.
|
167
175
|
|
168
176
|
For Non-Rails usage:
|
@@ -186,8 +194,8 @@ Quick Start
|
|
186
194
|
```ruby
|
187
195
|
class User < ActiveRecord::Base
|
188
196
|
attr_accessible :avatar
|
189
|
-
has_attached_file :avatar, :
|
190
|
-
validates_attachment_content_type :avatar, :
|
197
|
+
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
|
198
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
191
199
|
end
|
192
200
|
```
|
193
201
|
|
@@ -195,8 +203,8 @@ end
|
|
195
203
|
|
196
204
|
```ruby
|
197
205
|
class User < ActiveRecord::Base
|
198
|
-
has_attached_file :avatar, :
|
199
|
-
validates_attachment_content_type :avatar, :
|
206
|
+
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
|
207
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
200
208
|
end
|
201
209
|
```
|
202
210
|
|
@@ -219,7 +227,7 @@ end
|
|
219
227
|
### Edit and New Views
|
220
228
|
|
221
229
|
```erb
|
222
|
-
<%= form_for @user, :
|
230
|
+
<%= form_for @user, url: users_path, html: { multipart: true } do |form| %>
|
223
231
|
<%= form.file_field :avatar %>
|
224
232
|
<% end %>
|
225
233
|
```
|
@@ -296,7 +304,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
|
|
296
304
|
validation.
|
297
305
|
|
298
306
|
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).
|
307
|
+
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
300
308
|
|
301
309
|
Validations
|
302
310
|
-----------
|
@@ -310,9 +318,9 @@ For validations, Paperclip introduces several validators to validate your attach
|
|
310
318
|
Example Usage:
|
311
319
|
|
312
320
|
```ruby
|
313
|
-
validates :avatar, :
|
314
|
-
validates_with AttachmentPresenceValidator, :
|
315
|
-
validates_with AttachmentSizeValidator, :
|
321
|
+
validates :avatar, attachment_presence: true
|
322
|
+
validates_with AttachmentPresenceValidator, attributes: :avatar
|
323
|
+
validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 1.megabytes
|
316
324
|
|
317
325
|
```
|
318
326
|
|
@@ -331,9 +339,9 @@ validates_attachment_presence :avatar
|
|
331
339
|
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
|
332
340
|
|
333
341
|
```ruby
|
334
|
-
validates_attachment :avatar, :
|
335
|
-
:
|
336
|
-
:
|
342
|
+
validates_attachment :avatar, presence: true,
|
343
|
+
content_type: { content_type: "image/jpeg" },
|
344
|
+
size: { in: 0..10.kilobytes }
|
337
345
|
```
|
338
346
|
|
339
347
|
_NOTE: Post-processing will not even **start** if the attachment is not valid
|
@@ -391,7 +399,7 @@ image-y ones:
|
|
391
399
|
|
392
400
|
```ruby
|
393
401
|
validates_attachment :avatar,
|
394
|
-
:
|
402
|
+
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
395
403
|
```
|
396
404
|
|
397
405
|
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
|
@@ -399,6 +407,12 @@ inferred content_type, regardless of the actual contents of the file.
|
|
399
407
|
|
400
408
|
---
|
401
409
|
|
410
|
+
Internationalization (I18n)
|
411
|
+
---------------------------
|
412
|
+
|
413
|
+
For using or adding locale files in different languages, check the project
|
414
|
+
https://github.com/thoughtbot/paperclip-i18n.
|
415
|
+
|
402
416
|
Security Validations
|
403
417
|
====================
|
404
418
|
|
@@ -415,9 +429,9 @@ do this.
|
|
415
429
|
class ActiveRecord::Base
|
416
430
|
has_attached_file :avatar
|
417
431
|
# Validate content type
|
418
|
-
validates_attachment_content_type :avatar, :
|
432
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage/
|
419
433
|
# Validate filename
|
420
|
-
validates_attachment_file_name :avatar, :
|
434
|
+
validates_attachment_file_name :avatar, matches: [/png\Z/, /jpe?g\Z/]
|
421
435
|
# Explicitly do not validate
|
422
436
|
do_not_validate_attachment_file_type :avatar
|
423
437
|
end
|
@@ -460,7 +474,7 @@ module YourApp
|
|
460
474
|
class Application < Rails::Application
|
461
475
|
# Other code...
|
462
476
|
|
463
|
-
config.paperclip_defaults = {:
|
477
|
+
config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
|
464
478
|
end
|
465
479
|
end
|
466
480
|
```
|
@@ -471,7 +485,7 @@ An example Rails initializer would look something like this:
|
|
471
485
|
|
472
486
|
```ruby
|
473
487
|
Paperclip::Attachment.default_options[:storage] = :fog
|
474
|
-
Paperclip::Attachment.default_options[:fog_credentials] = {:
|
488
|
+
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
|
475
489
|
Paperclip::Attachment.default_options[:fog_directory] = ""
|
476
490
|
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
|
477
491
|
```
|
@@ -493,6 +507,7 @@ class CreateUsersWithAttachments < ActiveRecord::Migration
|
|
493
507
|
create_table :users do |t|
|
494
508
|
t.attachment :avatar
|
495
509
|
end
|
510
|
+
end
|
496
511
|
|
497
512
|
# This is assuming you are only using the users table for Paperclip attachment. Drop with care!
|
498
513
|
def down
|
@@ -566,7 +581,7 @@ gems along side with Paperclip:
|
|
566
581
|
The files that are assigned as attachments are, by default, placed in the
|
567
582
|
directory specified by the `:path` option to `has_attached_file`. By default, this
|
568
583
|
location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
|
569
|
-
This location was chosen because on standard Capistrano deployments, the
|
584
|
+
This location was chosen because, on standard Capistrano deployments, the
|
570
585
|
`public/system` directory is symlinked to the app's shared directory, meaning it
|
571
586
|
will survive between deployments. For example, using that `:path`, you may have a
|
572
587
|
file at
|
@@ -580,12 +595,15 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
|
|
580
595
|
the `aws-sdk` gem in your Gemfile:
|
581
596
|
|
582
597
|
```ruby
|
583
|
-
gem 'aws-sdk', '
|
598
|
+
gem 'aws-sdk', '>= 2.0.0' # If using paperclip `master` (upcoming v5.0)
|
584
599
|
```
|
585
600
|
|
586
601
|
And then you can specify using S3 from `has_attached_file`.
|
587
602
|
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).
|
603
|
+
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
604
|
+
|
605
|
+
_**NOTE**: If upgrading aws-sdk from v1.x to v2.x, be sure to read the
|
606
|
+
[UPGRADING guide](https://github.com/thoughtbot/paperclip/blob/master/UPGRADING)._
|
589
607
|
|
590
608
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
591
609
|
available to the internet at large. If you require access control, it's
|
@@ -610,20 +628,20 @@ processors. You can specify a processor with the `:processors` option to
|
|
610
628
|
`has_attached_file`:
|
611
629
|
|
612
630
|
```ruby
|
613
|
-
has_attached_file :scan, :
|
614
|
-
:
|
631
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
632
|
+
processors: [:ocr]
|
615
633
|
```
|
616
634
|
|
617
635
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
618
|
-
hash "{ :
|
636
|
+
hash "{ quality: :better }" passed to it along with the uploaded file. For
|
619
637
|
more information about defining processors, see Paperclip::Processor.
|
620
638
|
|
621
|
-
The default processor is Paperclip::Thumbnail. For
|
639
|
+
The default processor is Paperclip::Thumbnail. For backward compatibility
|
622
640
|
reasons, you can pass a single geometry string or an array containing a
|
623
641
|
geometry and a format that the file will be converted to, like so:
|
624
642
|
|
625
643
|
```ruby
|
626
|
-
has_attached_file :avatar, :
|
644
|
+
has_attached_file :avatar, styles: { thumb: ["32x32#", :png] }
|
627
645
|
```
|
628
646
|
|
629
647
|
This will convert the "thumb" style to a 32x32 square in PNG format, regardless
|
@@ -638,12 +656,12 @@ receive the same parameters, which are defined in the `:styles` hash.
|
|
638
656
|
For example, assuming we had this definition:
|
639
657
|
|
640
658
|
```ruby
|
641
|
-
has_attached_file :scan, :
|
642
|
-
:
|
659
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
660
|
+
processors: [:rotator, :ocr]
|
643
661
|
```
|
644
662
|
|
645
663
|
then both the :rotator processor and the :ocr processor would receive the
|
646
|
-
options `{ :
|
664
|
+
options `{ quality: :better }`. This parameter may not mean anything to one
|
647
665
|
or more or the processors, and they are expected to ignore it.
|
648
666
|
|
649
667
|
_NOTE: Because processors operate by turning the original attachment into the
|
@@ -699,8 +717,8 @@ Example Usage:
|
|
699
717
|
|
700
718
|
```ruby
|
701
719
|
has_attached_file :avatar, {
|
702
|
-
:
|
703
|
-
:
|
720
|
+
url: "/system/:hash.:extension",
|
721
|
+
hash_secret: "longSecretString"
|
704
722
|
}
|
705
723
|
```
|
706
724
|
|
@@ -738,7 +756,7 @@ An option is available to preserve attachments in order to play nicely with soft
|
|
738
756
|
|
739
757
|
```ruby
|
740
758
|
has_attached_file :some_attachment, {
|
741
|
-
:
|
759
|
+
preserve_files: "true",
|
742
760
|
}
|
743
761
|
```
|
744
762
|
|
@@ -786,7 +804,7 @@ look as follows where a boss will receive a `300x300` thumbnail otherwise a
|
|
786
804
|
|
787
805
|
```ruby
|
788
806
|
class User < ActiveRecord::Base
|
789
|
-
has_attached_file :avatar, :
|
807
|
+
has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } }
|
790
808
|
end
|
791
809
|
```
|
792
810
|
|
@@ -803,7 +821,7 @@ processors, where a defined `watermark` processor is invoked after the
|
|
803
821
|
|
804
822
|
```ruby
|
805
823
|
class User < ActiveRecord::Base
|
806
|
-
has_attached_file :avatar, :
|
824
|
+
has_attached_file :avatar, processors: lambda { |instance| instance.processors }
|
807
825
|
attr_accessor :processors
|
808
826
|
end
|
809
827
|
```
|
@@ -813,7 +831,7 @@ end
|
|
813
831
|
Logging
|
814
832
|
----------
|
815
833
|
|
816
|
-
By default Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this
|
834
|
+
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
835
|
```ruby
|
818
836
|
Your::Application.configure do
|
819
837
|
...
|
@@ -822,7 +840,7 @@ Your::Application.configure do
|
|
822
840
|
end
|
823
841
|
```
|
824
842
|
|
825
|
-
More information in the [rdocs](http://
|
843
|
+
More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip.options)
|
826
844
|
|
827
845
|
---
|
828
846
|
|
@@ -864,12 +882,12 @@ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` fil
|
|
864
882
|
|
865
883
|
```ruby
|
866
884
|
class User < ActiveRecord::Base
|
867
|
-
has_attached_file :avatar, :
|
885
|
+
has_attached_file :avatar, styles: { thumb: 'x100', croppable: '600x600>', big: '1000x1000>' }
|
868
886
|
end
|
869
887
|
|
870
888
|
class Book < ActiveRecord::Base
|
871
|
-
has_attached_file :cover, :
|
872
|
-
has_attached_file :sample, :
|
889
|
+
has_attached_file :cover, styles: { small: 'x100', large: '1000x1000>' }
|
890
|
+
has_attached_file :sample, styles: { thumb: 'x100' }
|
873
891
|
end
|
874
892
|
```
|
875
893
|
|
@@ -896,7 +914,7 @@ Testing
|
|
896
914
|
-------
|
897
915
|
|
898
916
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
899
|
-
documentation on [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
917
|
+
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
900
918
|
for more information.
|
901
919
|
|
902
920
|
**Parallel Tests**
|
@@ -953,12 +971,12 @@ guidelines:
|
|
953
971
|
|
954
972
|
Please see `CONTRIBUTING.md` for more details on contributing and running test.
|
955
973
|
|
956
|
-
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
|
974
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
|
957
975
|
|
958
976
|
License
|
959
977
|
-------
|
960
978
|
|
961
|
-
Paperclip is Copyright © 2008-
|
979
|
+
Paperclip is Copyright © 2008-2016 thoughtbot, inc. It is free software, and may be
|
962
980
|
redistributed under the terms specified in the MIT-LICENSE file.
|
963
981
|
|
964
982
|
About thoughtbot
|