@rails/activestorage 6.0.4 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +150 -180
  2. package/README.md +36 -4
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,278 +1,248 @@
1
- ## Rails 6.0.4 (June 15, 2021) ##
1
+ ## Rails 6.1.1 (January 07, 2021) ##
2
2
 
3
- * The Poppler PDF previewer renders a preview image using the original
4
- document's crop box rather than its media box, hiding print margins. This
5
- matches the behavior of the MuPDF previewer.
6
-
7
- *Vincent Robert*
8
-
9
-
10
- ## Rails 6.0.3.7 (May 05, 2021) ##
3
+ * Fix S3 multipart uploads when threshold is larger than file.
11
4
 
12
- * No changes.
5
+ *Matt Muller*
13
6
 
14
7
 
15
- ## Rails 6.0.3.6 (March 26, 2021) ##
8
+ ## Rails 6.1.0 (December 09, 2020) ##
16
9
 
17
- * Marcel is upgraded to version 1.0.0 to avoid a dependency on GPL-licensed
18
- mime types data.
19
-
20
- *George Claghorn*
10
+ * Change default queue name of the analysis (`:active_storage_analysis`) and
11
+ purge (`:active_storage_purge`) jobs to be the job adapter's default (`:default`).
21
12
 
13
+ *Rafael Mendonça França*
22
14
 
23
- ## Rails 6.0.3.5 (February 10, 2021) ##
15
+ * Implement `strict_loading` on ActiveStorage associations.
24
16
 
25
- * No changes.
17
+ *David Angulo*
26
18
 
19
+ * Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing`.
27
20
 
28
- ## Rails 6.0.3.4 (October 07, 2020) ##
21
+ *Rafael Mendonça França*
29
22
 
30
- * No changes.
23
+ * Remove deprecated `ActiveStorage::Transformers::MiniMagickTransformer`.
31
24
 
25
+ *Rafael Mendonça França*
32
26
 
33
- ## Rails 6.0.3.3 (September 09, 2020) ##
27
+ * Remove deprecated `config.active_storage.queue`.
34
28
 
35
- * No changes.
29
+ *Rafael Mendonça França*
36
30
 
31
+ * Remove deprecated `ActiveStorage::Downloading`.
37
32
 
38
- ## Rails 6.0.3.2 (June 17, 2020) ##
33
+ *Rafael Mendonça França*
39
34
 
40
- * No changes.
35
+ * Add per-environment configuration support
41
36
 
37
+ *Pietro Moro*
42
38
 
43
- ## Rails 6.0.3.1 (May 18, 2020) ##
44
-
45
- * [CVE-2020-8162] Include Content-Length in signature for ActiveStorage direct upload
39
+ * The Poppler PDF previewer renders a preview image using the original
40
+ document's crop box rather than its media box, hiding print margins. This
41
+ matches the behavior of the MuPDF previewer.
46
42
 
43
+ *Vincent Robert*
47
44
 
48
- ## Rails 6.0.3 (May 06, 2020) ##
45
+ * Touch parent model when an attachment is purged.
49
46
 
50
- * No changes.
47
+ *Víctor Pérez Rodríguez*
51
48
 
49
+ * Files can now be served by proxying them from the underlying storage service
50
+ instead of redirecting to a signed service URL. Use the
51
+ `rails_storage_proxy_path` and `_url` helpers to proxy an attached file:
52
52
 
53
- ## Rails 6.0.2.2 (March 19, 2020) ##
53
+ ```erb
54
+ <%= image_tag rails_storage_proxy_path(@user.avatar) %>
55
+ ```
54
56
 
55
- * No changes.
57
+ To proxy by default, set `config.active_storage.resolve_model_to_route`:
56
58
 
59
+ ```ruby
60
+ # Proxy attached files instead.
61
+ config.active_storage.resolve_model_to_route = :rails_storage_proxy
62
+ ```
57
63
 
58
- ## Rails 6.0.2.1 (December 18, 2019) ##
64
+ ```erb
65
+ <%= image_tag @user.avatar %>
66
+ ```
59
67
 
60
- * No changes.
68
+ To redirect to a signed service URL when the default file serving strategy
69
+ is set to proxying, use the `rails_storage_redirect_path` and `_url` helpers:
61
70
 
71
+ ```erb
72
+ <%= image_tag rails_storage_redirect_path(@user.avatar) %>
73
+ ```
62
74
 
63
- ## Rails 6.0.2 (December 13, 2019) ##
75
+ *Jonathan Fleckenstein*
64
76
 
65
- * No changes.
77
+ * Add `config.active_storage.web_image_content_types` to allow applications
78
+ to add content types (like `image/webp`) in which variants can be processed,
79
+ instead of letting those images be converted to the fallback PNG format.
66
80
 
81
+ *Jeroen van Haperen*
67
82
 
68
- ## Rails 6.0.1 (November 5, 2019) ##
83
+ * Add support for creating variants of `WebP` images out of the box.
69
84
 
70
- * `ActiveStorage::AnalyzeJob`s are discarded on `ActiveRecord::RecordNotFound` errors.
85
+ *Dino Maric*
71
86
 
72
- *George Claghorn*
87
+ * Only enqueue analysis jobs for blobs with non-null analyzer classes.
73
88
 
74
- * Blobs are recorded in the database before being uploaded to the service.
75
- This fixes that generated blob keys could silently collide, leading to
76
- data loss.
89
+ *Gannon McGibbon*
77
90
 
78
- *Julik Tarkhanov*
91
+ * Previews are created on the same service as the original blob.
79
92
 
93
+ *Peter Zhu*
80
94
 
81
- ## Rails 6.0.0 (August 16, 2019) ##
95
+ * Remove unused `disposition` and `content_type` query parameters for `DiskService`.
82
96
 
83
- * No changes.
97
+ *Peter Zhu*
84
98
 
99
+ * Use `DiskController` for both public and private files.
85
100
 
86
- ## Rails 6.0.0.rc2 (July 22, 2019) ##
101
+ `DiskController` is able to handle multiple services by adding a
102
+ `service_name` field in the generated URL in `DiskService`.
87
103
 
88
- * No changes.
104
+ *Peter Zhu*
89
105
 
106
+ * Variants are tracked in the database to avoid existence checks in the storage service.
90
107
 
91
- ## Rails 6.0.0.rc1 (April 24, 2019) ##
108
+ *George Claghorn*
92
109
 
93
- * Don't raise when analyzing an image whose type is unsupported by ImageMagick.
110
+ * Deprecate `service_url` methods in favour of `url`.
94
111
 
95
- Fixes #36065.
112
+ Deprecate `Variant#service_url` and `Preview#service_url` to instead use
113
+ `#url` method to be consistent with `Blob`.
96
114
 
97
- *Guilherme Mansur*
115
+ *Peter Zhu*
98
116
 
99
- * Permit generating variants of BMP images.
117
+ * Permanent URLs for public storage blobs.
100
118
 
101
- *Younes Serraj*
119
+ Services can be configured in `config/storage.yml` with a new key
120
+ `public: true | false` to indicate whether a service holds public
121
+ blobs or private blobs. Public services will always return a permanent URL.
102
122
 
123
+ Deprecates `Blob#service_url` in favor of `Blob#url`.
103
124
 
104
- ## Rails 6.0.0.beta3 (March 11, 2019) ##
125
+ *Peter Zhu*
105
126
 
106
- * No changes.
127
+ * Make services aware of configuration names.
107
128
 
129
+ *Gannon McGibbon*
108
130
 
109
- ## Rails 6.0.0.beta2 (February 25, 2019) ##
131
+ * The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
110
132
 
111
- * No changes.
133
+ *Kyle Ribordy*
112
134
 
135
+ * Allow storage services to be configured per attachment.
113
136
 
114
- ## Rails 6.0.0.beta1 (January 18, 2019) ##
137
+ ```ruby
138
+ class User < ActiveRecord::Base
139
+ has_one_attached :avatar, service: :s3
140
+ end
115
141
 
116
- * [Rename npm package](https://github.com/rails/rails/pull/34905) from
117
- [`activestorage`](https://www.npmjs.com/package/activestorage) to
118
- [`@rails/activestorage`](https://www.npmjs.com/package/@rails/activestorage).
142
+ class Gallery < ActiveRecord::Base
143
+ has_many_attached :photos, service: :s3
144
+ end
145
+ ```
119
146
 
120
- *Javan Makhmali*
147
+ *Dmitry Tsepelev*
121
148
 
122
- * Replace `config.active_storage.queue` with two options that indicate which
123
- queues analysis and purge jobs should use, respectively:
149
+ * You can optionally provide a custom blob key when attaching a new file:
124
150
 
125
- * `config.active_storage.queues.analysis`
126
- * `config.active_storage.queues.purge`
151
+ ```ruby
152
+ user.avatar.attach key: "avatars/#{user.id}.jpg",
153
+ io: io, content_type: "image/jpeg", filename: "avatar.jpg"
154
+ ```
127
155
 
128
- `config.active_storage.queue` is preferred over the new options when it's
129
- set, but it is deprecated and will be removed in Rails 6.1.
156
+ Active Storage will store the blob's data on the configured service at the provided key.
130
157
 
131
158
  *George Claghorn*
132
159
 
133
- * Permit generating variants of TIFF images.
134
-
135
- *Luciano Sousa*
160
+ * Replace `Blob.create_after_upload!` with `Blob.create_and_upload!` and deprecate the former.
136
161
 
137
- * Use base36 (all lowercase) for all new Blob keys to prevent
138
- collisions and undefined behavior with case-insensitive filesystems and
139
- database indices.
162
+ `create_after_upload!` has been removed since it could lead to data
163
+ corruption by uploading to a key on the storage service which happened to
164
+ be already taken. Creating the record would then correctly raise a
165
+ database uniqueness exception but the stored object would already have
166
+ overwritten another. `create_and_upload!` swaps the order of operations
167
+ so that the key gets reserved up-front or the uniqueness error gets raised,
168
+ before the upload to a key takes place.
140
169
 
141
170
  *Julik Tarkhanov*
142
171
 
143
- * It doesn’t include an `X-CSRF-Token` header if a meta tag is not found on
144
- the page. It previously included one with a value of `undefined`.
172
+ * Set content disposition in direct upload using `filename` and `disposition` parameters to `ActiveStorage::Service#headers_for_direct_upload`.
145
173
 
146
- *Cameron Bothner*
174
+ *Peter Zhu*
147
175
 
148
- * Fix `ArgumentError` when uploading to amazon s3
176
+ * Allow record to be optionally passed to blob finders to make sharding
177
+ easier.
149
178
 
150
- *Hiroki Sanpei*
179
+ *Gannon McGibbon*
151
180
 
152
- * Add progressive JPG to default list of variable content types
181
+ * Switch from `azure-storage` gem to `azure-storage-blob` gem for Azure service.
153
182
 
154
- *Maurice Kühlborn*
183
+ *Peter Zhu*
155
184
 
156
- * Add `ActiveStorage.routes_prefix` for configuring generated routes.
185
+ * Add `config.active_storage.draw_routes` to disable Active Storage routes.
157
186
 
158
- *Chris Bisnett*
187
+ *Gannon McGibbon*
159
188
 
160
- * `ActiveStorage::Service::AzureStorageService` only handles specifically
161
- relevant types of `Azure::Core::Http::HTTPError`. It previously obscured
162
- other types of `HTTPError`, which is the azure-storage gem’s catch-all
163
- exception class.
189
+ * Image analysis is skipped if ImageMagick returns an error.
164
190
 
165
- *Cameron Bothner*
166
-
167
- * `ActiveStorage::DiskController#show` generates a 404 Not Found response when
168
- the requested file is missing from the disk service. It previously raised
169
- `Errno::ENOENT`.
170
-
171
- *Cameron Bothner*
172
-
173
- * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
174
- `ActiveStorage::FileNotFoundError` when the corresponding file is missing
175
- from the storage service. Services translate service-specific missing object
176
- exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and
177
- `Errno::ENOENT` for the disk service) into
178
- `ActiveStorage::FileNotFoundError`.
179
-
180
- *Cameron Bothner*
181
-
182
- * Added the `ActiveStorage::SetCurrent` concern for custom Active Storage
183
- controllers that can't inherit from `ActiveStorage::BaseController`.
184
-
185
- *George Claghorn*
186
-
187
- * Active Storage error classes like `ActiveStorage::IntegrityError` and
188
- `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
189
- instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
190
- handle all Active Storage errors.
191
-
192
- *Andrei Makarov*, *George Claghorn*
193
-
194
- * Uploaded files assigned to a record are persisted to storage when the record
195
- is saved instead of immediately.
196
-
197
- In Rails 5.2, the following causes an uploaded file in `params[:avatar]` to
198
- be stored:
199
-
200
- ```ruby
201
- @user.avatar = params[:avatar]
202
- ```
203
-
204
- In Rails 6, the uploaded file is stored when `@user` is successfully saved.
191
+ `ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a
192
+ `MiniMagick::Error`, which caused persistent `ActiveStorage::AnalyzeJob`
193
+ failures. It now logs the error and returns `{}`, resulting in no metadata
194
+ being added to the offending image blob.
205
195
 
206
196
  *George Claghorn*
207
197
 
208
- * Add the ability to reflect on defined attachments using the existing
209
- ActiveRecord reflection mechanism.
198
+ * Method calls on singular attachments return `nil` when no file is attached.
210
199
 
211
- *Kevin Deisz*
212
-
213
- * Variant arguments of `false` or `nil` will no longer be passed to the
214
- processor. For example, the following will not have the monochrome
215
- variation applied:
200
+ Previously, assuming the following User model, `user.avatar.filename` would
201
+ raise a `Module::DelegationError` if no avatar was attached:
216
202
 
217
203
  ```ruby
218
- avatar.variant(monochrome: false)
204
+ class User < ApplicationRecord
205
+ has_one_attached :avatar
206
+ end
219
207
  ```
220
208
 
221
- *Jacob Smith*
209
+ They now return `nil`.
222
210
 
223
- * Generated attachment getter and setter methods are created
224
- within the model's `GeneratedAssociationMethods` module to
225
- allow overriding and composition using `super`.
211
+ *Matthew Tanous*
226
212
 
227
- *Josh Susser*, *Jamon Douglas*
213
+ * The mirror service supports direct uploads.
228
214
 
229
- * Add `ActiveStorage::Blob#open`, which downloads a blob to a tempfile on disk
230
- and yields the tempfile. Deprecate `ActiveStorage::Downloading`.
215
+ New files are directly uploaded to the primary service. When a
216
+ directly-uploaded file is attached to a record, a background job is enqueued
217
+ to copy it to each secondary service.
231
218
 
232
- *David Robertson*, *George Claghorn*
219
+ Configure the queue used to process mirroring jobs by setting
220
+ `config.active_storage.queues.mirror`. The default is `:active_storage_mirror`.
233
221
 
234
- * Pass in `identify: false` as an argument when providing a `content_type` for
235
- `ActiveStorage::Attached::{One,Many}#attach` to bypass automatic content
236
- type inference. For example:
222
+ *George Claghorn*
237
223
 
238
- ```ruby
239
- @message.image.attach(
240
- io: File.open('/path/to/file'),
241
- filename: 'file.pdf',
242
- content_type: 'application/pdf',
243
- identify: false
244
- )
224
+ * The S3 service now permits uploading files larger than 5 gigabytes.
225
+
226
+ When uploading a file greater than 100 megabytes in size, the service
227
+ transparently switches to [multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html)
228
+ using a part size computed from the file's total size and S3's part count limit.
229
+
230
+ No application changes are necessary to take advantage of this feature. You
231
+ can customize the default 100 MB multipart upload threshold in your S3
232
+ service's configuration:
233
+
234
+ ```yaml
235
+ production:
236
+ service: s3
237
+ access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
238
+ secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
239
+ region: us-east-1
240
+ bucket: my-bucket
241
+ upload:
242
+ multipart_threshold: <%= 250.megabytes %>
245
243
  ```
246
244
 
247
- *Ryan Davidson*
248
-
249
- * The Google Cloud Storage service properly supports streaming downloads.
250
- It now requires version 1.11 or newer of the google-cloud-storage gem.
251
-
252
245
  *George Claghorn*
253
246
 
254
- * Use the [ImageProcessing](https://github.com/janko-m/image_processing) gem
255
- for Active Storage variants, and deprecate the MiniMagick backend.
256
-
257
- This means that variants are now automatically oriented if the original
258
- image was rotated. Also, in addition to the existing ImageMagick
259
- operations, variants can now use `:resize_to_fit`, `:resize_to_fill`, and
260
- other ImageProcessing macros. These are now recommended over raw `:resize`,
261
- as they also sharpen the thumbnail after resizing.
262
-
263
- The ImageProcessing gem also comes with a backend implemented on
264
- [libvips](http://jcupitt.github.io/libvips/), an alternative to
265
- ImageMagick which has significantly better performance than
266
- ImageMagick in most cases, both in terms of speed and memory usage. In
267
- Active Storage it's now possible to switch to the libvips backend by
268
- changing `Rails.application.config.active_storage.variant_processor` to
269
- `:vips`.
270
-
271
- *Janko Marohnić*
272
-
273
- * Rails 6 requires Ruby 2.5.0 or newer.
274
-
275
- *Jeremy Daer*, *Kasper Timm Hansen*
276
-
277
247
 
278
- Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.
248
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activestorage/CHANGELOG.md) for previous changes.
package/README.md CHANGED
@@ -10,13 +10,13 @@ You can read more about Active Storage in the [Active Storage Overview](https://
10
10
 
11
11
  ## Compared to other storage solutions
12
12
 
13
- A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/rails/blob/main/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/main/activestorage/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the `Attachment` join model, which then connects to the actual `Blob`.
13
+ A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the `Attachment` join model, which then connects to the actual `Blob`.
14
14
 
15
15
  `Blob` models store attachment metadata (filename, content-type, etc.), and their identifier key in the storage service. Blob models do not store the actual binary data. They are intended to be immutable in spirit. One file, one blob. You can associate the same blob with multiple application models as well. And if you want to do transformations of a given `Blob`, the idea is that you'll simply create a new one, rather than attempt to mutate the existing one (though of course you can delete the previous version later if you don't need it).
16
16
 
17
17
  ## Installation
18
18
 
19
- Run `rails active_storage:install` to copy over active_storage migrations.
19
+ Run `bin/rails active_storage:install` to copy over active_storage migrations.
20
20
 
21
21
  NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.
22
22
 
@@ -55,7 +55,7 @@ url_for(user.avatar)
55
55
 
56
56
  class AvatarsController < ApplicationController
57
57
  def update
58
- # params[:avatar] contains a ActionDispatch::Http::UploadedFile object
58
+ # params[:avatar] contains an ActionDispatch::Http::UploadedFile object
59
59
  Current.user.avatar.attach(params.require(:avatar))
60
60
  redirect_to Current.user
61
61
  end
@@ -106,6 +106,37 @@ Variation of image attachment:
106
106
  <%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
107
107
  ```
108
108
 
109
+ ## File serving strategies
110
+
111
+ Active Storage supports two ways to serve files: redirecting and proxying.
112
+
113
+ ### Redirecting
114
+
115
+ Active Storage generates stable application URLs for files which, when accessed, redirect to signed, short-lived service URLs. This relieves application servers of the burden of serving file data. It is the default file serving strategy.
116
+
117
+ When the application is configured to proxy files by default, use the `rails_storage_redirect_path` and `_url` route helpers to redirect instead:
118
+
119
+ ```erb
120
+ <%= image_tag rails_storage_redirect_path(@user.avatar) %>
121
+ ```
122
+
123
+ ### Proxying
124
+
125
+ Optionally, files can be proxied instead. This means that your application servers will download file data from the storage service in response to requests. This can be useful for serving files from a CDN.
126
+
127
+ Explicitly proxy attachments using the `rails_storage_proxy_path` and `_url` route helpers:
128
+
129
+ ```erb
130
+ <%= image_tag rails_storage_proxy_path(@user.avatar) %>
131
+ ```
132
+
133
+ Or configure Active Storage to use proxying by default:
134
+
135
+ ```ruby
136
+ # config/initializers/active_storage.rb
137
+ Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
138
+ ```
139
+
109
140
  ## Direct uploads
110
141
 
111
142
  Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.
@@ -120,7 +151,8 @@ Active Storage, with its included JavaScript library, supports uploading directl
120
151
  ```
121
152
  Using the npm package:
122
153
  ```js
123
- require("@rails/activestorage").start()
154
+ import * as ActiveStorage from "@rails/activestorage"
155
+ ActiveStorage.start()
124
156
  ```
125
157
  2. Annotate file inputs with the direct upload URL.
126
158
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@rails/activestorage",
3
- "version": "6.0.4",
3
+ "version": "6.1.1",
4
4
  "description": "Attach cloud and local files in Rails applications",
5
5
  "main": "app/assets/javascripts/activestorage.js",
6
6
  "files": [
7
7
  "app/assets/javascripts/*.js",
8
8
  "src/*.js"
9
9
  ],
10
- "homepage": "http://rubyonrails.org/",
10
+ "homepage": "https://rubyonrails.org/",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/rails/rails.git"