activestorage 6.0.5.1 → 6.1.7.3

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