activestorage 6.0.4.1 → 6.1.0.rc1

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