activestorage 6.1.7.10 → 7.0.0

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +150 -309
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +25 -11
  5. data/app/assets/javascripts/activestorage.esm.js +856 -0
  6. data/app/assets/javascripts/activestorage.js +270 -377
  7. data/app/controllers/active_storage/base_controller.rb +1 -10
  8. data/app/controllers/active_storage/blobs/proxy_controller.rb +14 -5
  9. data/app/controllers/active_storage/blobs/redirect_controller.rb +6 -4
  10. data/app/controllers/active_storage/direct_uploads_controller.rb +7 -1
  11. data/app/controllers/active_storage/disk_controller.rb +1 -0
  12. data/app/controllers/active_storage/representations/base_controller.rb +5 -1
  13. data/app/controllers/active_storage/representations/proxy_controller.rb +6 -5
  14. data/app/controllers/active_storage/representations/redirect_controller.rb +6 -4
  15. data/app/controllers/concerns/active_storage/set_blob.rb +6 -2
  16. data/app/controllers/concerns/active_storage/set_current.rb +3 -3
  17. data/app/controllers/concerns/active_storage/streaming.rb +65 -0
  18. data/app/javascript/activestorage/blob_record.js +10 -3
  19. data/app/javascript/activestorage/direct_upload.js +4 -2
  20. data/app/javascript/activestorage/direct_upload_controller.js +9 -1
  21. data/app/javascript/activestorage/ujs.js +1 -1
  22. data/app/models/active_storage/attachment.rb +35 -2
  23. data/app/models/active_storage/blob/representable.rb +7 -5
  24. data/app/models/active_storage/blob.rb +92 -36
  25. data/app/models/active_storage/current.rb +12 -2
  26. data/app/models/active_storage/preview.rb +6 -4
  27. data/app/models/active_storage/record.rb +1 -1
  28. data/app/models/active_storage/variant.rb +6 -9
  29. data/app/models/active_storage/variant_record.rb +2 -0
  30. data/app/models/active_storage/variant_with_record.rb +9 -5
  31. data/app/models/active_storage/variation.rb +3 -3
  32. data/config/routes.rb +10 -10
  33. data/db/migrate/20170806125915_create_active_storage_tables.rb +14 -5
  34. data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +0 -4
  35. data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +0 -2
  36. data/db/update_migrate/20211119233751_remove_not_null_on_active_storage_blobs_checksum.rb +5 -0
  37. data/lib/active_storage/analyzer/audio_analyzer.rb +65 -0
  38. data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +39 -0
  39. data/lib/active_storage/analyzer/image_analyzer/vips.rb +49 -0
  40. data/lib/active_storage/analyzer/image_analyzer.rb +2 -30
  41. data/lib/active_storage/analyzer/video_analyzer.rb +26 -11
  42. data/lib/active_storage/analyzer.rb +8 -4
  43. data/lib/active_storage/attached/changes/create_many.rb +7 -3
  44. data/lib/active_storage/attached/changes/create_one.rb +1 -1
  45. data/lib/active_storage/attached/changes/create_one_of_many.rb +1 -1
  46. data/lib/active_storage/attached/changes/delete_many.rb +1 -1
  47. data/lib/active_storage/attached/changes/delete_one.rb +1 -1
  48. data/lib/active_storage/attached/changes/detach_many.rb +18 -0
  49. data/lib/active_storage/attached/changes/detach_one.rb +24 -0
  50. data/lib/active_storage/attached/changes/purge_many.rb +27 -0
  51. data/lib/active_storage/attached/changes/purge_one.rb +27 -0
  52. data/lib/active_storage/attached/changes.rb +7 -1
  53. data/lib/active_storage/attached/many.rb +27 -15
  54. data/lib/active_storage/attached/model.rb +35 -7
  55. data/lib/active_storage/attached/one.rb +32 -27
  56. data/lib/active_storage/direct_upload_token.rb +59 -0
  57. data/lib/active_storage/downloader.rb +4 -4
  58. data/lib/active_storage/engine.rb +42 -16
  59. data/lib/active_storage/errors.rb +3 -0
  60. data/lib/active_storage/fixture_set.rb +76 -0
  61. data/lib/active_storage/gem_version.rb +4 -4
  62. data/lib/active_storage/previewer/video_previewer.rb +0 -2
  63. data/lib/active_storage/previewer.rb +4 -4
  64. data/lib/active_storage/reflection.rb +12 -2
  65. data/lib/active_storage/service/azure_storage_service.rb +28 -6
  66. data/lib/active_storage/service/configurator.rb +1 -1
  67. data/lib/active_storage/service/disk_service.rb +24 -19
  68. data/lib/active_storage/service/gcs_service.rb +109 -11
  69. data/lib/active_storage/service/mirror_service.rb +2 -2
  70. data/lib/active_storage/service/registry.rb +1 -1
  71. data/lib/active_storage/service/s3_service.rb +37 -15
  72. data/lib/active_storage/service.rb +13 -5
  73. data/lib/active_storage/transformers/image_processing_transformer.rb +1 -66
  74. data/lib/active_storage/transformers/transformer.rb +1 -1
  75. data/lib/active_storage.rb +6 -292
  76. metadata +27 -17
  77. data/app/controllers/concerns/active_storage/disable_session.rb +0 -12
  78. data/app/controllers/concerns/active_storage/set_headers.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7210176f90dfcb16101844584d3c0c6d37f3996085f6b0103a1e5a6001756273
4
- data.tar.gz: 65e005fc682e993bd2f35ef01422337d0a25d298834c4fe1fa6560dead731d3b
3
+ metadata.gz: 85a5cf62726ae4b98295bb1b62926f4f2fa15257babdb8d6251cff37c682c354
4
+ data.tar.gz: 65f662b546c7f3e5eaf0775f065174f6d7162721578d763213eefd2875565a7b
5
5
  SHA512:
6
- metadata.gz: b6dca260b33a644eb54c94514f6943b63b2935ba1736b9e2ce3af4f2dba2aaa854e01d5d0ac323e87b9dac4f1c8f2b3ee04d8935d28583956265b8de805d490e
7
- data.tar.gz: f5890441b9d8be4edb20b0d637e3e9e6eff0fc7844c0e12a3d9ba907f1227c117e81e8f538206c0478be8a8b72cf3ac1f1d37ba7e02eaa7e0fdc03d5e9f285c1
6
+ metadata.gz: 3ff136a959f672bb822be34f573209a3017744a8ba476e8f6e2ec3de11130b9fb1bf4e876ee2b0233b1a2bfa9acd66d211b2b9b329f533b9449fd8d084482ec6
7
+ data.tar.gz: 1d38c4402a276a86847c492c1d373fab6ace21b6149e03426744561a1528307947f4353645b53db5bdf32cfa4776aa0c15cfd0591631bdc554be66b481f5d77e
data/CHANGELOG.md CHANGED
@@ -1,80 +1,65 @@
1
- ## Rails 6.1.7.10 (October 23, 2024) ##
2
-
3
- * No changes.
4
-
5
-
6
- ## Rails 6.1.7.9 (October 15, 2024) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 6.1.7.8 (June 04, 2024) ##
12
-
13
- * No changes.
1
+ ## Rails 7.0.0 (December 15, 2021) ##
14
2
 
3
+ * Support transforming empty-ish `has_many_attached` value into `[]` (e.g. `[""]`).
15
4
 
16
- ## Rails 6.1.7.7 (February 21, 2024) ##
17
-
18
- * Disables the session in `ActiveStorage::Blobs::ProxyController`
19
- and `ActiveStorage::Representations::ProxyController`
20
- in order to allow caching by default in some CDNs as CloudFlare
21
-
22
- Fixes #44136
23
-
24
- *Bruno Prieto*
25
-
26
- ## Rails 6.1.7.6 (August 22, 2023) ##
5
+ ```ruby
6
+ @user.highlights = [""]
7
+ @user.highlights # => []
8
+ ```
27
9
 
28
- * No changes.
10
+ *Sean Doyle*
29
11
 
30
12
 
31
- ## Rails 6.1.7.5 (August 22, 2023) ##
13
+ ## Rails 7.0.0.rc3 (December 14, 2021) ##
32
14
 
33
15
  * No changes.
34
16
 
35
17
 
36
- ## Rails 6.1.7.4 (June 26, 2023) ##
18
+ ## Rails 7.0.0.rc2 (December 14, 2021) ##
37
19
 
38
20
  * No changes.
39
21
 
22
+ ## Rails 7.0.0.rc1 (December 06, 2021) ##
40
23
 
41
- ## Rails 6.1.7.3 (March 13, 2023) ##
42
-
43
- * No changes.
24
+ * `Add ActiveStorage::Blob.compose` to concatenate multiple blobs.
44
25
 
26
+ *Gannon McGibbon*
45
27
 
46
- ## Rails 6.1.7.2 (January 24, 2023) ##
28
+ * Setting custom metadata on blobs are now persisted to remote storage.
47
29
 
48
- * No changes.
30
+ *joshuamsager*
49
31
 
32
+ * Support direct uploads to multiple services.
50
33
 
51
- ## Rails 6.1.7.1 (January 17, 2023) ##
34
+ *Dmitry Tsepelev*
52
35
 
53
- * No changes.
36
+ * Invalid default content types are deprecated
54
37
 
38
+ Blobs created with content_type `image/jpg`, `image/pjpeg`, `image/bmp`, `text/javascript` will now produce
39
+ a deprecation warning, since these are not valid content types.
55
40
 
56
- ## Rails 6.1.7 (September 09, 2022) ##
41
+ These content types will be removed from the defaults in Rails 7.1.
57
42
 
58
- * Respect Active Record's primary_key_type in Active Storage migrations. Backported from 7.0.
43
+ You can set `config.active_storage.silence_invalid_content_types_warning = true` to dismiss the warning.
59
44
 
60
- *fatkodima*
45
+ *Alex Ghiculescu*
61
46
 
62
- ## Rails 6.1.6.1 (July 12, 2022) ##
47
+ ## Rails 7.0.0.alpha2 (September 15, 2021) ##
63
48
 
64
49
  * No changes.
65
50
 
66
51
 
67
- ## Rails 6.1.6 (May 09, 2022) ##
52
+ ## Rails 7.0.0.alpha1 (September 15, 2021) ##
68
53
 
69
- * No changes.
54
+ * Emit Active Support instrumentation events from Active Storage analyzers.
70
55
 
56
+ Fixes #42930
71
57
 
72
- ## Rails 6.1.5.1 (April 26, 2022) ##
58
+ *Shouichi Kamiya*
73
59
 
74
- * No changes.
60
+ * Add support for byte range requests
75
61
 
76
-
77
- ## Rails 6.1.5 (March 09, 2022) ##
62
+ *Tom Prats*
78
63
 
79
64
  * Attachments can be deleted after their association is no longer defined.
80
65
 
@@ -82,350 +67,206 @@
82
67
 
83
68
  *Don Sisco*
84
69
 
70
+ * Make `vips` the default variant processor for new apps.
85
71
 
86
- ## Rails 6.1.4.7 (March 08, 2022) ##
87
-
88
- * Added image transformation validation via configurable allow-list.
89
-
90
- Variant now offers a configurable allow-list for
91
- transformation methods in addition to a configurable deny-list for arguments.
92
-
93
- [CVE-2022-21831]
94
-
95
-
96
- ## Rails 6.1.4.6 (February 11, 2022) ##
97
-
98
- * No changes.
99
-
100
-
101
- ## Rails 6.1.4.5 (February 11, 2022) ##
102
-
103
- * No changes.
104
-
105
-
106
- ## Rails 6.1.4.4 (December 15, 2021) ##
107
-
108
- * No changes.
109
-
110
-
111
- ## Rails 6.1.4.3 (December 14, 2021) ##
112
-
113
- * No changes.
114
-
115
-
116
- ## Rails 6.1.4.2 (December 14, 2021) ##
117
-
118
- * No changes.
119
-
120
-
121
- ## Rails 6.1.4.1 (August 19, 2021) ##
122
-
123
- * No changes.
124
-
125
-
126
- ## Rails 6.1.4 (June 24, 2021) ##
127
-
128
- * The parameters sent to `ffmpeg` for generating a video preview image are now
129
- configurable under `config.active_storage.video_preview_arguments`.
130
-
131
- *Brendon Muir*
132
-
133
- * Fix Active Storage update task when running in an engine.
134
-
135
- *Justin Malčić*
72
+ See the upgrade guide for instructions on converting from `mini_magick` to `vips`. `mini_magick` is
73
+ not deprecated, existing apps can keep using it.
136
74
 
137
- * Don't raise an error if the mime type is not recognized.
75
+ *Breno Gazzola*
138
76
 
139
- Fixes #41777.
77
+ * Deprecate `ActiveStorage::Current.host` in favor of `ActiveStorage::Current.url_options` which accepts
78
+ a host, protocol and port.
140
79
 
141
- *Alex Ghiculescu*
142
-
143
- * `ActiveStorage::PreviewError` is raised when a previewer is unable to generate a preview image.
144
-
145
- *Alex Robbin*
146
-
147
- * respond with 404 given invalid variation key when asking for representations.
148
-
149
- *George Claghorn*
150
-
151
- * `Blob` creation shouldn't crash if no service selected.
152
-
153
- *Alex Ghiculescu*
154
-
155
-
156
- ## Rails 6.1.3.2 (May 05, 2021) ##
157
-
158
- * No changes.
80
+ *Santiago Bartesaghi*
159
81
 
82
+ * Allow using [IAM](https://cloud.google.com/storage/docs/access-control/signed-urls) when signing URLs with GCS.
160
83
 
161
- ## Rails 6.1.3.1 (March 26, 2021) ##
162
-
163
- * Marcel is upgraded to version 1.0.0 to avoid a dependency on GPL-licensed
164
- mime types data.
165
-
166
- *George Claghorn*
167
-
168
-
169
- ## Rails 6.1.3 (February 17, 2021) ##
170
-
171
- * No changes.
84
+ ```yaml
85
+ gcs:
86
+ service: GCS
87
+ ...
88
+ iam: true
89
+ ```
172
90
 
91
+ *RRethy*
173
92
 
174
- ## Rails 6.1.2.1 (February 10, 2021) ##
93
+ * OpenSSL constants are now used for Digest computations.
175
94
 
176
- * No changes.
95
+ *Dirkjan Bussink*
177
96
 
97
+ * Deprecate `config.active_storage.replace_on_assign_to_many`. Future versions of Rails
98
+ will behave the same way as when the config is set to `true`.
178
99
 
179
- ## Rails 6.1.2 (February 09, 2021) ##
100
+ *Santiago Bartesaghi*
180
101
 
181
- * No changes.
102
+ * Remove deprecated methods: `build_after_upload`, `create_after_upload!` in favor of `create_and_upload!`,
103
+ and `service_url` in favor of `url`.
182
104
 
105
+ *Santiago Bartesaghi*
183
106
 
184
- ## Rails 6.1.1 (January 07, 2021) ##
107
+ * Add support of `strict_loading_by_default` to `ActiveStorage::Representations` controllers.
185
108
 
186
- * Fix S3 multipart uploads when threshold is larger than file.
109
+ *Anton Topchii*, *Andrew White*
187
110
 
188
- *Matt Muller*
111
+ * Allow to detach an attachment when record is not persisted.
189
112
 
113
+ *Jacopo Beschi*
190
114
 
191
- ## Rails 6.1.0 (December 09, 2020) ##
115
+ * Use libvips instead of ImageMagick to analyze images when `active_storage.variant_processor = vips`.
192
116
 
193
- * Change default queue name of the analysis (`:active_storage_analysis`) and
194
- purge (`:active_storage_purge`) jobs to be the job adapter's default (`:default`).
117
+ *Breno Gazzola*
195
118
 
196
- *Rafael Mendonça França*
119
+ * Add metadata value for presence of video channel in video blobs.
197
120
 
198
- * Implement `strict_loading` on ActiveStorage associations.
121
+ The `metadata` attribute of video blobs has a new boolean key named `video` that is set to
122
+ `true` if the file has an video channel and `false` if it doesn't.
199
123
 
200
- *David Angulo*
124
+ *Breno Gazzola*
201
125
 
202
- * Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing`.
126
+ * Deprecate usage of `purge` and `purge_later` from the association extension.
203
127
 
204
- *Rafael Mendonça França*
128
+ *Jacopo Beschi*
205
129
 
206
- * Remove deprecated `ActiveStorage::Transformers::MiniMagickTransformer`.
130
+ * Passing extra parameters in `ActiveStorage::Blob#url` to S3 Client.
207
131
 
208
- *Rafael Mendonça França*
132
+ This allows calls of `ActiveStorage::Blob#url` to have more interaction with
133
+ the S3 Presigner, enabling, amongst other options, custom S3 domain URL
134
+ Generation.
209
135
 
210
- * Remove deprecated `config.active_storage.queue`.
211
-
212
- *Rafael Mendonça França*
213
-
214
- * Remove deprecated `ActiveStorage::Downloading`.
136
+ ```ruby
137
+ blob = ActiveStorage::Blob.last
215
138
 
216
- *Rafael Mendonça França*
139
+ blob.url # => https://<bucket-name>.s3.<region>.amazonaws.com/<key>
140
+ blob.url(virtual_host: true) # => # => https://<bucket-name>/<key>
141
+ ```
217
142
 
218
- * Add per-environment configuration support
143
+ *josegomezr*
219
144
 
220
- *Pietro Moro*
145
+ * Allow setting a `Cache-Control` on files uploaded to GCS.
221
146
 
222
- * The Poppler PDF previewer renders a preview image using the original
223
- document's crop box rather than its media box, hiding print margins. This
224
- matches the behavior of the MuPDF previewer.
147
+ ```yaml
148
+ gcs:
149
+ service: GCS
150
+ ...
151
+ cache_control: "public, max-age=3600"
152
+ ```
225
153
 
226
- *Vincent Robert*
154
+ *maleblond*
227
155
 
228
- * Touch parent model when an attachment is purged.
156
+ * The parameters sent to `ffmpeg` for generating a video preview image are now
157
+ configurable under `config.active_storage.video_preview_arguments`.
229
158
 
230
- *Víctor Pérez Rodríguez*
159
+ *Brendon Muir*
231
160
 
232
- * Files can now be served by proxying them from the underlying storage service
233
- instead of redirecting to a signed service URL. Use the
234
- `rails_storage_proxy_path` and `_url` helpers to proxy an attached file:
161
+ * The ActiveStorage video previewer will now use scene change detection to generate
162
+ better preview images (rather than the previous default of using the first frame
163
+ of the video). This change requires FFmpeg v3.4+.
235
164
 
236
- ```erb
237
- <%= image_tag rails_storage_proxy_path(@user.avatar) %>
238
- ```
165
+ *Jonathan Hefner*
239
166
 
240
- To proxy by default, set `config.active_storage.resolve_model_to_route`:
167
+ * Add support for ActiveStorage expiring URLs.
241
168
 
242
169
  ```ruby
243
- # Proxy attached files instead.
244
- config.active_storage.resolve_model_to_route = :rails_storage_proxy
245
- ```
246
-
247
- ```erb
248
- <%= image_tag @user.avatar %>
249
- ```
250
-
251
- To redirect to a signed service URL when the default file serving strategy
252
- is set to proxying, use the `rails_storage_redirect_path` and `_url` helpers:
170
+ rails_blob_path(user.avatar, disposition: "attachment", expires_in: 30.minutes)
253
171
 
254
- ```erb
255
- <%= image_tag rails_storage_redirect_path(@user.avatar) %>
172
+ <%= image_tag rails_blob_path(user.avatar.variant(resize: "100x100"), expires_in: 30.minutes) %>
256
173
  ```
257
174
 
258
- *Jonathan Fleckenstein*
175
+ If you want to set default expiration time for ActiveStorage URLs throughout your application, set `config.active_storage.urls_expire_in`.
259
176
 
260
- * Add `config.active_storage.web_image_content_types` to allow applications
261
- to add content types (like `image/webp`) in which variants can be processed,
262
- instead of letting those images be converted to the fallback PNG format.
177
+ *aki77*
263
178
 
264
- *Jeroen van Haperen*
179
+ * Allow to purge an attachment when record is not persisted for `has_many_attached`.
265
180
 
266
- * Add support for creating variants of `WebP` images out of the box.
181
+ *Jacopo Beschi*
267
182
 
268
- *Dino Maric*
183
+ * Add `with_all_variant_records` method to eager load all variant records on an attachment at once.
184
+ `with_attached_image` scope now eager loads variant records if using variant tracking.
269
185
 
270
- * Only enqueue analysis jobs for blobs with non-null analyzer classes.
271
-
272
- *Gannon McGibbon*
273
-
274
- * Previews are created on the same service as the original blob.
275
-
276
- *Peter Zhu*
186
+ *Alex Ghiculescu*
277
187
 
278
- * Remove unused `disposition` and `content_type` query parameters for `DiskService`.
188
+ * Add metadata value for presence of audio channel in video blobs.
279
189
 
280
- *Peter Zhu*
190
+ The `metadata` attribute of video blobs has a new boolean key named `audio` that is set to
191
+ `true` if the file has an audio channel and `false` if it doesn't.
281
192
 
282
- * Use `DiskController` for both public and private files.
193
+ *Breno Gazzola*
283
194
 
284
- `DiskController` is able to handle multiple services by adding a
285
- `service_name` field in the generated URL in `DiskService`.
195
+ * Adds analyzer for audio files.
286
196
 
287
- *Peter Zhu*
197
+ *Breno Gazzola*
288
198
 
289
- * Variants are tracked in the database to avoid existence checks in the storage service.
199
+ * Respect Active Record's primary_key_type in Active Storage migrations.
290
200
 
291
- *George Claghorn*
201
+ *fatkodima*
292
202
 
293
- * Deprecate `service_url` methods in favour of `url`.
203
+ * Allow `expires_in` for ActiveStorage signed ids.
294
204
 
295
- Deprecate `Variant#service_url` and `Preview#service_url` to instead use
296
- `#url` method to be consistent with `Blob`.
205
+ *aki77*
297
206
 
298
- *Peter Zhu*
207
+ * Allow to purge an attachment when record is not persisted for `has_one_attached`.
299
208
 
300
- * Permanent URLs for public storage blobs.
209
+ *Jacopo Beschi*
301
210
 
302
- Services can be configured in `config/storage.yml` with a new key
303
- `public: true | false` to indicate whether a service holds public
304
- blobs or private blobs. Public services will always return a permanent URL.
211
+ * Add a load hook called `active_storage_variant_record` (providing `ActiveStorage::VariantRecord`)
212
+ to allow for overriding aspects of the `ActiveStorage::VariantRecord` class. This makes
213
+ `ActiveStorage::VariantRecord` consistent with `ActiveStorage::Blob` and `ActiveStorage::Attachment`
214
+ that already have load hooks.
305
215
 
306
- Deprecates `Blob#service_url` in favor of `Blob#url`.
216
+ *Brendon Muir*
307
217
 
308
- *Peter Zhu*
218
+ * `ActiveStorage::PreviewError` is raised when a previewer is unable to generate a preview image.
309
219
 
310
- * Make services aware of configuration names.
220
+ *Alex Robbin*
311
221
 
312
- *Gannon McGibbon*
222
+ * Add `ActiveStorage::Streaming` module that can be included in a controller to get access to `#send_blob_stream`,
223
+ which wraps the new `ActionController::Base#send_stream` method to stream a blob from cloud storage:
313
224
 
314
- * The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
225
+ ```ruby
226
+ class MyPublicBlobsController < ApplicationController
227
+ include ActiveStorage::SetBlob, ActiveStorage::Streaming
228
+
229
+ def show
230
+ http_cache_forever(public: true) do
231
+ send_blob_stream @blob, disposition: params[:disposition]
232
+ end
233
+ end
234
+ end
235
+ ```
315
236
 
316
- *Kyle Ribordy*
237
+ *DHH*
317
238
 
318
- * Allow storage services to be configured per attachment.
239
+ * Add ability to use pre-defined variants.
319
240
 
320
241
  ```ruby
321
242
  class User < ActiveRecord::Base
322
- has_one_attached :avatar, service: :s3
243
+ has_one_attached :avatar do |attachable|
244
+ attachable.variant :thumb, resize: "100x100"
245
+ attachable.variant :medium, resize: "300x300", monochrome: true
246
+ end
323
247
  end
324
248
 
325
249
  class Gallery < ActiveRecord::Base
326
- has_many_attached :photos, service: :s3
250
+ has_many_attached :photos do |attachable|
251
+ attachable.variant :thumb, resize: "100x100"
252
+ attachable.variant :medium, resize: "300x300", monochrome: true
253
+ end
327
254
  end
328
- ```
329
255
 
330
- *Dmitry Tsepelev*
331
-
332
- * You can optionally provide a custom blob key when attaching a new file:
333
-
334
- ```ruby
335
- user.avatar.attach key: "avatars/#{user.id}.jpg",
336
- io: io, content_type: "image/jpeg", filename: "avatar.jpg"
256
+ <%= image_tag user.avatar.variant(:thumb) %>
337
257
  ```
338
258
 
339
- Active Storage will store the blob's data on the configured service at the provided key.
340
-
341
- *George Claghorn*
342
-
343
- * Replace `Blob.create_after_upload!` with `Blob.create_and_upload!` and deprecate the former.
344
-
345
- `create_after_upload!` has been removed since it could lead to data
346
- corruption by uploading to a key on the storage service which happened to
347
- be already taken. Creating the record would then correctly raise a
348
- database uniqueness exception but the stored object would already have
349
- overwritten another. `create_and_upload!` swaps the order of operations
350
- so that the key gets reserved up-front or the uniqueness error gets raised,
351
- before the upload to a key takes place.
352
-
353
- *Julik Tarkhanov*
354
-
355
- * Set content disposition in direct upload using `filename` and `disposition` parameters to `ActiveStorage::Service#headers_for_direct_upload`.
356
-
357
- *Peter Zhu*
358
-
359
- * Allow record to be optionally passed to blob finders to make sharding
360
- easier.
361
-
362
- *Gannon McGibbon*
363
-
364
- * Switch from `azure-storage` gem to `azure-storage-blob` gem for Azure service.
365
-
366
- *Peter Zhu*
367
-
368
- * Add `config.active_storage.draw_routes` to disable Active Storage routes.
369
-
370
- *Gannon McGibbon*
371
-
372
- * Image analysis is skipped if ImageMagick returns an error.
373
-
374
- `ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a
375
- `MiniMagick::Error`, which caused persistent `ActiveStorage::AnalyzeJob`
376
- failures. It now logs the error and returns `{}`, resulting in no metadata
377
- being added to the offending image blob.
378
-
379
- *George Claghorn*
380
-
381
- * Method calls on singular attachments return `nil` when no file is attached.
382
-
383
- Previously, assuming the following User model, `user.avatar.filename` would
384
- raise a `Module::DelegationError` if no avatar was attached:
385
-
386
- ```ruby
387
- class User < ApplicationRecord
388
- has_one_attached :avatar
389
- end
390
- ```
391
-
392
- They now return `nil`.
393
-
394
- *Matthew Tanous*
395
-
396
- * The mirror service supports direct uploads.
397
-
398
- New files are directly uploaded to the primary service. When a
399
- directly-uploaded file is attached to a record, a background job is enqueued
400
- to copy it to each secondary service.
401
-
402
- Configure the queue used to process mirroring jobs by setting
403
- `config.active_storage.queues.mirror`. The default is `:active_storage_mirror`.
404
-
405
- *George Claghorn*
406
-
407
- * The S3 service now permits uploading files larger than 5 gigabytes.
259
+ *fatkodima*
408
260
 
409
- When uploading a file greater than 100 megabytes in size, the service
410
- transparently switches to [multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html)
411
- using a part size computed from the file's total size and S3's part count limit.
261
+ * After setting `config.active_storage.resolve_model_to_route = :rails_storage_proxy`
262
+ `rails_blob_path` and `rails_representation_path` will generate proxy URLs by default.
412
263
 
413
- No application changes are necessary to take advantage of this feature. You
414
- can customize the default 100 MB multipart upload threshold in your S3
415
- service's configuration:
264
+ *Ali Ismayilov*
416
265
 
417
- ```yaml
418
- production:
419
- service: s3
420
- access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
421
- secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
422
- region: us-east-1
423
- bucket: my-bucket
424
- upload:
425
- multipart_threshold: <%= 250.megabytes %>
426
- ```
266
+ * Declare `ActiveStorage::FixtureSet` and `ActiveStorage::FixtureSet.blob` to
267
+ improve fixture integration.
427
268
 
428
- *George Claghorn*
269
+ *Sean Doyle*
429
270
 
430
271
 
431
- Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activestorage/CHANGELOG.md) for previous changes.
272
+ Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activestorage/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2022 David Heinemeier Hansson, Basecamp
1
+ Copyright (c) 2017-2021 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
@@ -32,7 +32,7 @@ class User < ApplicationRecord
32
32
  end
33
33
 
34
34
  # Attach an avatar to the user.
35
- user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
35
+ user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpeg")
36
36
 
37
37
  # Does the user have an avatar?
38
38
  user.avatar.attached? # => true
@@ -88,8 +88,7 @@ class MessagesController < ApplicationController
88
88
  end
89
89
 
90
90
  def create
91
- message = Message.create! params.require(:message).permit(:title, :content)
92
- message.images.attach(params[:message][:images])
91
+ message = Message.create! params.require(:message).permit(:title, :content, images: [])
93
92
  redirect_to message
94
93
  end
95
94
 
@@ -124,27 +123,42 @@ When the application is configured to proxy files by default, use the `rails_sto
124
123
 
125
124
  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
125
 
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:
126
+ You can configure Active Storage to use proxying by default:
134
127
 
135
128
  ```ruby
136
129
  # config/initializers/active_storage.rb
137
130
  Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
138
131
  ```
139
132
 
133
+ Or if you want to explicitly proxy specific attachments there are URL helpers you can use in the form of `rails_storage_proxy_path` and `rails_storage_proxy_url`.
134
+
135
+ ```erb
136
+ <%= image_tag rails_storage_proxy_path(@user.avatar) %>
137
+ ```
138
+
140
139
  ## Direct uploads
141
140
 
142
141
  Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.
143
142
 
144
143
  ### Direct upload installation
145
144
 
146
- 1. Include `activestorage.js` in your application's JavaScript bundle.
145
+ 1. Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.
147
146
 
147
+ Requiring directly without bundling through the asset pipeline in the application html with autostart:
148
+ ```html
149
+ <%= javascript_include_tag "activestorage" %>
150
+ ```
151
+ Requiring via importmap-rails without bundling through the asset pipeline in the application html without autostart as ESM:
152
+ ```ruby
153
+ # config/importmap.rb
154
+ pin "@rails/activestorage", to: "activestorage.esm.js"
155
+ ```
156
+ ```html
157
+ <script type="module-shim">
158
+ import * as ActiveStorage from "@rails/activestorage"
159
+ ActiveStorage.start()
160
+ </script>
161
+ ```
148
162
  Using the asset pipeline:
149
163
  ```js
150
164
  //= require activestorage