activestorage 6.0.6 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activestorage might be problematic. Click here for more details.

Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +142 -239
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +36 -4
  5. data/app/controllers/active_storage/base_controller.rb +11 -0
  6. data/app/controllers/active_storage/blobs/proxy_controller.rb +14 -0
  7. data/app/controllers/active_storage/{blobs_controller.rb → blobs/redirect_controller.rb} +2 -2
  8. data/app/controllers/active_storage/direct_uploads_controller.rb +1 -1
  9. data/app/controllers/active_storage/disk_controller.rb +8 -20
  10. data/app/controllers/active_storage/representations/proxy_controller.rb +19 -0
  11. data/app/controllers/active_storage/{representations_controller.rb → representations/redirect_controller.rb} +2 -2
  12. data/app/controllers/concerns/active_storage/file_server.rb +18 -0
  13. data/app/controllers/concerns/active_storage/set_blob.rb +1 -1
  14. data/app/controllers/concerns/active_storage/set_current.rb +2 -2
  15. data/app/controllers/concerns/active_storage/set_headers.rb +12 -0
  16. data/app/jobs/active_storage/mirror_job.rb +15 -0
  17. data/app/models/active_storage/attachment.rb +18 -10
  18. data/app/models/active_storage/blob/analyzable.rb +6 -2
  19. data/app/models/active_storage/blob/identifiable.rb +7 -6
  20. data/app/models/active_storage/blob/representable.rb +34 -4
  21. data/app/models/active_storage/blob.rb +114 -57
  22. data/app/models/active_storage/preview.rb +31 -10
  23. data/app/models/active_storage/record.rb +7 -0
  24. data/app/models/active_storage/variant.rb +28 -41
  25. data/app/models/active_storage/variant_record.rb +8 -0
  26. data/app/models/active_storage/variant_with_record.rb +54 -0
  27. data/app/models/active_storage/variation.rb +25 -20
  28. data/config/routes.rb +58 -8
  29. data/db/migrate/20170806125915_create_active_storage_tables.rb +14 -5
  30. data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +17 -0
  31. data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +11 -0
  32. data/lib/active_storage/analyzer/image_analyzer.rb +3 -0
  33. data/lib/active_storage/analyzer/null_analyzer.rb +4 -0
  34. data/lib/active_storage/analyzer/video_analyzer.rb +14 -3
  35. data/lib/active_storage/analyzer.rb +6 -0
  36. data/lib/active_storage/attached/changes/create_many.rb +1 -0
  37. data/lib/active_storage/attached/changes/create_one.rb +17 -4
  38. data/lib/active_storage/attached/many.rb +4 -3
  39. data/lib/active_storage/attached/model.rb +67 -14
  40. data/lib/active_storage/attached/one.rb +4 -3
  41. data/lib/active_storage/engine.rb +25 -43
  42. data/lib/active_storage/gem_version.rb +2 -2
  43. data/lib/active_storage/log_subscriber.rb +6 -0
  44. data/lib/active_storage/previewer/mupdf_previewer.rb +3 -3
  45. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +2 -2
  46. data/lib/active_storage/previewer/video_previewer.rb +2 -2
  47. data/lib/active_storage/previewer.rb +3 -2
  48. data/lib/active_storage/service/azure_storage_service.rb +40 -35
  49. data/lib/active_storage/service/configurator.rb +3 -1
  50. data/lib/active_storage/service/disk_service.rb +36 -31
  51. data/lib/active_storage/service/gcs_service.rb +18 -16
  52. data/lib/active_storage/service/mirror_service.rb +31 -7
  53. data/lib/active_storage/service/registry.rb +32 -0
  54. data/lib/active_storage/service/s3_service.rb +51 -23
  55. data/lib/active_storage/service.rb +35 -7
  56. data/lib/active_storage/transformers/image_processing_transformer.rb +13 -365
  57. data/lib/active_storage/transformers/transformer.rb +0 -3
  58. data/lib/active_storage.rb +9 -8
  59. metadata +58 -23
  60. data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +0 -9
  61. data/lib/active_storage/downloading.rb +0 -47
  62. data/lib/active_storage/transformers/mini_magick_transformer.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96f84ce47ebd446d8955c31fd3ea858ec1cd7efb3b502c788a94f12ead13ff4c
4
- data.tar.gz: e0c80f5c00c2d1b88ebd135753cb1b5290e80c8912bb299348d21343ba69e0f0
3
+ metadata.gz: 623160c71aa10ece4e5d6d190081b87af9820e5a588fafa76a75bf1b767aa79d
4
+ data.tar.gz: 3722a36a91ad23e172458149e6e7938f97567a572d627c724bd0139e44330623
5
5
  SHA512:
6
- metadata.gz: cf2b2760b5f1399bb205e5290bec4dc5979f1e9e0389e6f599e71c26124009c907eecbaae8efa40aa5b6d819b73e05e7958f2e5d19054437d93282b03ad17994
7
- data.tar.gz: 054b5c52bf476bd16e8f4abe8fb614b1a693e672d629e5d31f26c48f357e2fb0c42fe6fec266d9a4fe6e933f46926f1fc89dbadb863da97c6785e8674f7a6ec4
6
+ metadata.gz: aa33e53ae13fe387177b90a0ce3e0a6936ebaa2238c798993d3f884f01cec75d29cc926002e307613097a644eb69860347b233d881746213ecc3763ca39872bb
7
+ data.tar.gz: 383e9977c3e00b57cfbc05d92ab8ca323f9f185a4bf45f57fcb2e57b11304ab8a8ba4db50fcc11234f296b4f53ab3bbed35597a6d9741c3c4f468b05bb020079
data/CHANGELOG.md CHANGED
@@ -1,64 +1,33 @@
1
- ## Rails 6.0.6 (September 09, 2022) ##
1
+ ## Rails 6.1.0 (December 09, 2020) ##
2
2
 
3
- * No changes.
3
+ * Change default queue name of the analysis (`:active_storage_analysis`) and
4
+ purge (`:active_storage_purge`) jobs to be the job adapter's default (`:default`).
4
5
 
6
+ *Rafael Mendonça França*
5
7
 
6
- ## Rails 6.0.5.1 (July 12, 2022) ##
8
+ * Implement `strict_loading` on ActiveStorage associations.
7
9
 
8
- * No changes.
10
+ *David Angulo*
9
11
 
12
+ * Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing`.
10
13
 
11
- ## Rails 6.0.5 (May 09, 2022) ##
14
+ *Rafael Mendonça França*
12
15
 
13
- * No changes.
16
+ * Remove deprecated `ActiveStorage::Transformers::MiniMagickTransformer`.
14
17
 
18
+ *Rafael Mendonça França*
15
19
 
16
- ## Rails 6.0.4.8 (April 26, 2022) ##
20
+ * Remove deprecated `config.active_storage.queue`.
17
21
 
18
- * No changes.
22
+ *Rafael Mendonça França*
19
23
 
24
+ * Remove deprecated `ActiveStorage::Downloading`.
20
25
 
21
- ## Rails 6.0.4.7 (March 08, 2022) ##
26
+ *Rafael Mendonça França*
22
27
 
23
- * Added image transformation validation via configurable allow-list.
24
-
25
- Variant now offers a configurable allow-list for
26
- transformation methods in addition to a configurable deny-list for arguments.
27
-
28
- [CVE-2022-21831]
28
+ * Add per-environment configuration support
29
29
 
30
-
31
- ## Rails 6.0.4.6 (February 11, 2022) ##
32
-
33
- * No changes.
34
-
35
-
36
- ## Rails 6.0.4.5 (February 11, 2022) ##
37
-
38
- * No changes.
39
-
40
-
41
- ## Rails 6.0.4.4 (December 15, 2021) ##
42
-
43
- * No changes.
44
-
45
-
46
- ## Rails 6.0.4.3 (December 14, 2021) ##
47
-
48
- * No changes.
49
-
50
-
51
- ## Rails 6.0.4.2 (December 14, 2021) ##
52
-
53
- * No changes.
54
-
55
-
56
- ## Rails 6.0.4.1 (August 19, 2021) ##
57
-
58
- * No changes.
59
-
60
-
61
- ## Rails 6.0.4 (June 15, 2021) ##
30
+ *Pietro Moro*
62
31
 
63
32
  * The Poppler PDF previewer renders a preview image using the original
64
33
  document's crop box rather than its media box, hiding print margins. This
@@ -66,273 +35,207 @@
66
35
 
67
36
  *Vincent Robert*
68
37
 
38
+ * Touch parent model when an attachment is purged.
69
39
 
70
- ## Rails 6.0.3.7 (May 05, 2021) ##
71
-
72
- * No changes.
40
+ *Víctor Pérez Rodríguez*
73
41
 
42
+ * Files can now be served by proxying them from the underlying storage service
43
+ instead of redirecting to a signed service URL. Use the
44
+ `rails_storage_proxy_path` and `_url` helpers to proxy an attached file:
74
45
 
75
- ## Rails 6.0.3.6 (March 26, 2021) ##
76
-
77
- * Marcel is upgraded to version 1.0.0 to avoid a dependency on GPL-licensed
78
- mime types data.
79
-
80
- *George Claghorn*
81
-
82
-
83
- ## Rails 6.0.3.5 (February 10, 2021) ##
84
-
85
- * No changes.
86
-
87
-
88
- ## Rails 6.0.3.4 (October 07, 2020) ##
89
-
90
- * No changes.
91
-
92
-
93
- ## Rails 6.0.3.3 (September 09, 2020) ##
94
-
95
- * No changes.
96
-
46
+ ```erb
47
+ <%= image_tag rails_storage_proxy_path(@user.avatar) %>
48
+ ```
97
49
 
98
- ## Rails 6.0.3.2 (June 17, 2020) ##
50
+ To proxy by default, set `config.active_storage.resolve_model_to_route`:
99
51
 
100
- * No changes.
52
+ ```ruby
53
+ # Proxy attached files instead.
54
+ config.active_storage.resolve_model_to_route = :rails_storage_proxy
55
+ ```
101
56
 
57
+ ```erb
58
+ <%= image_tag @user.avatar %>
59
+ ```
102
60
 
103
- ## Rails 6.0.3.1 (May 18, 2020) ##
61
+ To redirect to a signed service URL when the default file serving strategy
62
+ is set to proxying, use the `rails_storage_redirect_path` and `_url` helpers:
104
63
 
105
- * [CVE-2020-8162] Include Content-Length in signature for ActiveStorage direct upload
64
+ ```erb
65
+ <%= image_tag rails_storage_redirect_path(@user.avatar) %>
66
+ ```
106
67
 
68
+ *Jonathan Fleckenstein*
107
69
 
108
- ## Rails 6.0.3 (May 06, 2020) ##
70
+ * Add `config.active_storage.web_image_content_types` to allow applications
71
+ to add content types (like `image/webp`) in which variants can be processed,
72
+ instead of letting those images be converted to the fallback PNG format.
109
73
 
110
- * No changes.
74
+ *Jeroen van Haperen*
111
75
 
76
+ * Add support for creating variants of `WebP` images out of the box.
112
77
 
113
- ## Rails 6.0.2.2 (March 19, 2020) ##
78
+ *Dino Maric*
114
79
 
115
- * No changes.
80
+ * Only enqueue analysis jobs for blobs with non-null analyzer classes.
116
81
 
82
+ *Gannon McGibbon*
117
83
 
118
- ## Rails 6.0.2.1 (December 18, 2019) ##
84
+ * Previews are created on the same service as the original blob.
119
85
 
120
- * No changes.
86
+ *Peter Zhu*
121
87
 
88
+ * Remove unused `disposition` and `content_type` query parameters for `DiskService`.
122
89
 
123
- ## Rails 6.0.2 (December 13, 2019) ##
90
+ *Peter Zhu*
124
91
 
125
- * No changes.
92
+ * Use `DiskController` for both public and private files.
126
93
 
94
+ `DiskController` is able to handle multiple services by adding a
95
+ `service_name` field in the generated URL in `DiskService`.
127
96
 
128
- ## Rails 6.0.1 (November 5, 2019) ##
97
+ *Peter Zhu*
129
98
 
130
- * `ActiveStorage::AnalyzeJob`s are discarded on `ActiveRecord::RecordNotFound` errors.
99
+ * Variants are tracked in the database to avoid existence checks in the storage service.
131
100
 
132
101
  *George Claghorn*
133
102
 
134
- * Blobs are recorded in the database before being uploaded to the service.
135
- This fixes that generated blob keys could silently collide, leading to
136
- data loss.
137
-
138
- *Julik Tarkhanov*
139
-
140
-
141
- ## Rails 6.0.0 (August 16, 2019) ##
142
-
143
- * No changes.
144
-
145
-
146
- ## Rails 6.0.0.rc2 (July 22, 2019) ##
103
+ * Deprecate `service_url` methods in favour of `url`.
147
104
 
148
- * No changes.
105
+ Deprecate `Variant#service_url` and `Preview#service_url` to instead use
106
+ `#url` method to be consistent with `Blob`.
149
107
 
108
+ *Peter Zhu*
150
109
 
151
- ## Rails 6.0.0.rc1 (April 24, 2019) ##
110
+ * Permanent URLs for public storage blobs.
152
111
 
153
- * Don't raise when analyzing an image whose type is unsupported by ImageMagick.
112
+ Services can be configured in `config/storage.yml` with a new key
113
+ `public: true | false` to indicate whether a service holds public
114
+ blobs or private blobs. Public services will always return a permanent URL.
154
115
 
155
- Fixes #36065.
116
+ Deprecates `Blob#service_url` in favor of `Blob#url`.
156
117
 
157
- *Guilherme Mansur*
118
+ *Peter Zhu*
158
119
 
159
- * Permit generating variants of BMP images.
120
+ * Make services aware of configuration names.
160
121
 
161
- *Younes Serraj*
122
+ *Gannon McGibbon*
162
123
 
124
+ * The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
163
125
 
164
- ## Rails 6.0.0.beta3 (March 11, 2019) ##
126
+ *Kyle Ribordy*
165
127
 
166
- * No changes.
128
+ * Allow storage services to be configured per attachment.
167
129
 
130
+ ```ruby
131
+ class User < ActiveRecord::Base
132
+ has_one_attached :avatar, service: :s3
133
+ end
168
134
 
169
- ## Rails 6.0.0.beta2 (February 25, 2019) ##
170
-
171
- * No changes.
172
-
173
-
174
- ## Rails 6.0.0.beta1 (January 18, 2019) ##
175
-
176
- * [Rename npm package](https://github.com/rails/rails/pull/34905) from
177
- [`activestorage`](https://www.npmjs.com/package/activestorage) to
178
- [`@rails/activestorage`](https://www.npmjs.com/package/@rails/activestorage).
135
+ class Gallery < ActiveRecord::Base
136
+ has_many_attached :photos, service: :s3
137
+ end
138
+ ```
179
139
 
180
- *Javan Makhmali*
140
+ *Dmitry Tsepelev*
181
141
 
182
- * Replace `config.active_storage.queue` with two options that indicate which
183
- queues analysis and purge jobs should use, respectively:
142
+ * You can optionally provide a custom blob key when attaching a new file:
184
143
 
185
- * `config.active_storage.queues.analysis`
186
- * `config.active_storage.queues.purge`
144
+ ```ruby
145
+ user.avatar.attach key: "avatars/#{user.id}.jpg",
146
+ io: io, content_type: "image/jpeg", filename: "avatar.jpg"
147
+ ```
187
148
 
188
- `config.active_storage.queue` is preferred over the new options when it's
189
- set, but it is deprecated and will be removed in Rails 6.1.
149
+ Active Storage will store the blob's data on the configured service at the provided key.
190
150
 
191
151
  *George Claghorn*
192
152
 
193
- * Permit generating variants of TIFF images.
153
+ * Replace `Blob.create_after_upload!` with `Blob.create_and_upload!` and deprecate the former.
194
154
 
195
- *Luciano Sousa*
196
-
197
- * Use base36 (all lowercase) for all new Blob keys to prevent
198
- collisions and undefined behavior with case-insensitive filesystems and
199
- database indices.
155
+ `create_after_upload!` has been removed since it could lead to data
156
+ corruption by uploading to a key on the storage service which happened to
157
+ be already taken. Creating the record would then correctly raise a
158
+ database uniqueness exception but the stored object would already have
159
+ overwritten another. `create_and_upload!` swaps the order of operations
160
+ so that the key gets reserved up-front or the uniqueness error gets raised,
161
+ before the upload to a key takes place.
200
162
 
201
163
  *Julik Tarkhanov*
202
164
 
203
- * It doesn’t include an `X-CSRF-Token` header if a meta tag is not found on
204
- the page. It previously included one with a value of `undefined`.
205
-
206
- *Cameron Bothner*
207
-
208
- * Fix `ArgumentError` when uploading to amazon s3
209
-
210
- *Hiroki Sanpei*
211
-
212
- * Add progressive JPG to default list of variable content types
213
-
214
- *Maurice Kühlborn*
215
-
216
- * Add `ActiveStorage.routes_prefix` for configuring generated routes.
165
+ * Set content disposition in direct upload using `filename` and `disposition` parameters to `ActiveStorage::Service#headers_for_direct_upload`.
217
166
 
218
- *Chris Bisnett*
167
+ *Peter Zhu*
219
168
 
220
- * `ActiveStorage::Service::AzureStorageService` only handles specifically
221
- relevant types of `Azure::Core::Http::HTTPError`. It previously obscured
222
- other types of `HTTPError`, which is the azure-storage gem’s catch-all
223
- exception class.
169
+ * Allow record to be optionally passed to blob finders to make sharding
170
+ easier.
224
171
 
225
- *Cameron Bothner*
172
+ *Gannon McGibbon*
226
173
 
227
- * `ActiveStorage::DiskController#show` generates a 404 Not Found response when
228
- the requested file is missing from the disk service. It previously raised
229
- `Errno::ENOENT`.
174
+ * Switch from `azure-storage` gem to `azure-storage-blob` gem for Azure service.
230
175
 
231
- *Cameron Bothner*
176
+ *Peter Zhu*
232
177
 
233
- * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
234
- `ActiveStorage::FileNotFoundError` when the corresponding file is missing
235
- from the storage service. Services translate service-specific missing object
236
- exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and
237
- `Errno::ENOENT` for the disk service) into
238
- `ActiveStorage::FileNotFoundError`.
178
+ * Add `config.active_storage.draw_routes` to disable Active Storage routes.
239
179
 
240
- *Cameron Bothner*
180
+ *Gannon McGibbon*
241
181
 
242
- * Added the `ActiveStorage::SetCurrent` concern for custom Active Storage
243
- controllers that can't inherit from `ActiveStorage::BaseController`.
182
+ * Image analysis is skipped if ImageMagick returns an error.
244
183
 
245
- *George Claghorn*
246
-
247
- * Active Storage error classes like `ActiveStorage::IntegrityError` and
248
- `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
249
- instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
250
- handle all Active Storage errors.
251
-
252
- *Andrei Makarov*, *George Claghorn*
253
-
254
- * Uploaded files assigned to a record are persisted to storage when the record
255
- is saved instead of immediately.
256
-
257
- In Rails 5.2, the following causes an uploaded file in `params[:avatar]` to
258
- be stored:
259
-
260
- ```ruby
261
- @user.avatar = params[:avatar]
262
- ```
263
-
264
- In Rails 6, the uploaded file is stored when `@user` is successfully saved.
184
+ `ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a
185
+ `MiniMagick::Error`, which caused persistent `ActiveStorage::AnalyzeJob`
186
+ failures. It now logs the error and returns `{}`, resulting in no metadata
187
+ being added to the offending image blob.
265
188
 
266
189
  *George Claghorn*
267
190
 
268
- * Add the ability to reflect on defined attachments using the existing
269
- ActiveRecord reflection mechanism.
270
-
271
- *Kevin Deisz*
191
+ * Method calls on singular attachments return `nil` when no file is attached.
272
192
 
273
- * Variant arguments of `false` or `nil` will no longer be passed to the
274
- processor. For example, the following will not have the monochrome
275
- variation applied:
193
+ Previously, assuming the following User model, `user.avatar.filename` would
194
+ raise a `Module::DelegationError` if no avatar was attached:
276
195
 
277
196
  ```ruby
278
- avatar.variant(monochrome: false)
197
+ class User < ApplicationRecord
198
+ has_one_attached :avatar
199
+ end
279
200
  ```
280
201
 
281
- *Jacob Smith*
202
+ They now return `nil`.
282
203
 
283
- * Generated attachment getter and setter methods are created
284
- within the model's `GeneratedAssociationMethods` module to
285
- allow overriding and composition using `super`.
204
+ *Matthew Tanous*
286
205
 
287
- *Josh Susser*, *Jamon Douglas*
206
+ * The mirror service supports direct uploads.
288
207
 
289
- * Add `ActiveStorage::Blob#open`, which downloads a blob to a tempfile on disk
290
- and yields the tempfile. Deprecate `ActiveStorage::Downloading`.
208
+ New files are directly uploaded to the primary service. When a
209
+ directly-uploaded file is attached to a record, a background job is enqueued
210
+ to copy it to each secondary service.
291
211
 
292
- *David Robertson*, *George Claghorn*
212
+ Configure the queue used to process mirroring jobs by setting
213
+ `config.active_storage.queues.mirror`. The default is `:active_storage_mirror`.
293
214
 
294
- * Pass in `identify: false` as an argument when providing a `content_type` for
295
- `ActiveStorage::Attached::{One,Many}#attach` to bypass automatic content
296
- type inference. For example:
215
+ *George Claghorn*
297
216
 
298
- ```ruby
299
- @message.image.attach(
300
- io: File.open('/path/to/file'),
301
- filename: 'file.pdf',
302
- content_type: 'application/pdf',
303
- identify: false
304
- )
217
+ * The S3 service now permits uploading files larger than 5 gigabytes.
218
+
219
+ When uploading a file greater than 100 megabytes in size, the service
220
+ transparently switches to [multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html)
221
+ using a part size computed from the file's total size and S3's part count limit.
222
+
223
+ No application changes are necessary to take advantage of this feature. You
224
+ can customize the default 100 MB multipart upload threshold in your S3
225
+ service's configuration:
226
+
227
+ ```yaml
228
+ production:
229
+ service: s3
230
+ access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
231
+ secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
232
+ region: us-east-1
233
+ bucket: my-bucket
234
+ upload:
235
+ multipart_threshold: <%= 250.megabytes %>
305
236
  ```
306
237
 
307
- *Ryan Davidson*
308
-
309
- * The Google Cloud Storage service properly supports streaming downloads.
310
- It now requires version 1.11 or newer of the google-cloud-storage gem.
311
-
312
238
  *George Claghorn*
313
239
 
314
- * Use the [ImageProcessing](https://github.com/janko-m/image_processing) gem
315
- for Active Storage variants, and deprecate the MiniMagick backend.
316
-
317
- This means that variants are now automatically oriented if the original
318
- image was rotated. Also, in addition to the existing ImageMagick
319
- operations, variants can now use `:resize_to_fit`, `:resize_to_fill`, and
320
- other ImageProcessing macros. These are now recommended over raw `:resize`,
321
- as they also sharpen the thumbnail after resizing.
322
-
323
- The ImageProcessing gem also comes with a backend implemented on
324
- [libvips](http://jcupitt.github.io/libvips/), an alternative to
325
- ImageMagick which has significantly better performance than
326
- ImageMagick in most cases, both in terms of speed and memory usage. In
327
- Active Storage it's now possible to switch to the libvips backend by
328
- changing `Rails.application.config.active_storage.variant_processor` to
329
- `:vips`.
330
-
331
- *Janko Marohnić*
332
-
333
- * Rails 6 requires Ruby 2.5.0 or newer.
334
-
335
- *Jeremy Daer*, *Kasper Timm Hansen*
336
-
337
240
 
338
- Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.
241
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activestorage/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2019 David Heinemeier Hansson, Basecamp
1
+ Copyright (c) 2017-2020 David Heinemeier Hansson, Basecamp
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/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
 
@@ -5,4 +5,15 @@ class ActiveStorage::BaseController < ActionController::Base
5
5
  include ActiveStorage::SetCurrent
6
6
 
7
7
  protect_from_forgery with: :exception
8
+
9
+ self.etag_with_template_digest = false
10
+
11
+ private
12
+ def stream(blob)
13
+ blob.download do |chunk|
14
+ response.stream.write chunk
15
+ end
16
+ ensure
17
+ response.stream.close
18
+ end
8
19
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Proxy files through application. This avoids having a redirect and makes files easier to cache.
4
+ class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController
5
+ include ActiveStorage::SetBlob
6
+ include ActiveStorage::SetHeaders
7
+
8
+ def show
9
+ http_cache_forever public: true do
10
+ set_content_headers_from @blob
11
+ stream @blob
12
+ end
13
+ end
14
+ end
@@ -4,11 +4,11 @@
4
4
  # Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
5
5
  # security-through-obscurity factor of the signed blob references, you'll need to implement your own
6
6
  # authenticated redirection controller.
7
- class ActiveStorage::BlobsController < ActiveStorage::BaseController
7
+ class ActiveStorage::Blobs::RedirectController < ActiveStorage::BaseController
8
8
  include ActiveStorage::SetBlob
9
9
 
10
10
  def show
11
11
  expires_in ActiveStorage.service_urls_expire_in
12
- redirect_to @blob.service_url(disposition: params[:disposition])
12
+ redirect_to @blob.url(disposition: params[:disposition])
13
13
  end
14
14
  end
@@ -11,7 +11,7 @@ class ActiveStorage::DirectUploadsController < ActiveStorage::BaseController
11
11
 
12
12
  private
13
13
  def blob_args
14
- params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys
14
+ params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, metadata: {}).to_h.symbolize_keys
15
15
  end
16
16
 
17
17
  def direct_upload_json(blob)