activestorage 7.0.7.2 → 7.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +157 -294
- data/MIT-LICENSE +1 -1
- data/README.md +6 -6
- data/app/assets/javascripts/activestorage.esm.js +8 -4
- data/app/assets/javascripts/activestorage.js +9 -3
- data/app/controllers/active_storage/blobs/proxy_controller.rb +1 -0
- data/app/controllers/active_storage/disk_controller.rb +4 -2
- data/app/controllers/active_storage/representations/proxy_controller.rb +1 -0
- data/app/controllers/concerns/active_storage/disable_session.rb +12 -0
- data/app/controllers/concerns/active_storage/file_server.rb +4 -1
- data/app/javascript/activestorage/blob_record.js +4 -1
- data/app/javascript/activestorage/direct_upload.js +3 -2
- data/app/javascript/activestorage/index.js +3 -1
- data/app/jobs/active_storage/analyze_job.rb +1 -1
- data/app/jobs/active_storage/mirror_job.rb +1 -1
- data/app/jobs/active_storage/purge_job.rb +1 -1
- data/app/jobs/active_storage/transform_job.rb +12 -0
- data/app/models/active_storage/attachment.rb +87 -13
- data/app/models/active_storage/blob/analyzable.rb +4 -3
- data/app/models/active_storage/blob/identifiable.rb +1 -0
- data/app/models/active_storage/blob/representable.rb +7 -3
- data/app/models/active_storage/blob.rb +26 -46
- data/app/models/active_storage/current.rb +0 -10
- data/app/models/active_storage/filename.rb +2 -0
- data/app/models/active_storage/named_variant.rb +21 -0
- data/app/models/active_storage/preview.rb +5 -3
- data/app/models/active_storage/variant.rb +8 -7
- data/app/models/active_storage/variant_with_record.rb +19 -7
- data/app/models/active_storage/variation.rb +5 -3
- data/config/routes.rb +6 -4
- data/db/migrate/20170806125915_create_active_storage_tables.rb +1 -1
- data/lib/active_storage/analyzer/audio_analyzer.rb +16 -4
- data/lib/active_storage/analyzer/image_analyzer.rb +2 -0
- data/lib/active_storage/analyzer/video_analyzer.rb +3 -1
- data/lib/active_storage/analyzer.rb +2 -0
- data/lib/active_storage/attached/changes/create_many.rb +8 -3
- data/lib/active_storage/attached/changes/create_one.rb +45 -3
- data/lib/active_storage/attached/many.rb +5 -4
- data/lib/active_storage/attached/model.rb +66 -43
- data/lib/active_storage/attached/one.rb +5 -4
- data/lib/active_storage/attached.rb +2 -0
- data/lib/active_storage/deprecator.rb +7 -0
- data/lib/active_storage/engine.rb +11 -7
- data/lib/active_storage/fixture_set.rb +3 -1
- data/lib/active_storage/gem_version.rb +4 -4
- data/lib/active_storage/log_subscriber.rb +12 -0
- data/lib/active_storage/previewer.rb +8 -1
- data/lib/active_storage/reflection.rb +3 -3
- data/lib/active_storage/service/azure_storage_service.rb +2 -0
- data/lib/active_storage/service/disk_service.rb +2 -0
- data/lib/active_storage/service/gcs_service.rb +11 -20
- data/lib/active_storage/service/mirror_service.rb +10 -5
- data/lib/active_storage/service/s3_service.rb +2 -0
- data/lib/active_storage/service.rb +4 -2
- data/lib/active_storage/transformers/transformer.rb +2 -0
- data/lib/active_storage/version.rb +1 -1
- data/lib/active_storage.rb +19 -3
- metadata +18 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd39ea012892aff2a2c0feb20519b806a0615da59c4ad5939beef933484e19c0
|
4
|
+
data.tar.gz: 9f6b7e9e6fe58b73c288655c266e90534692df771523452952bdc252f9196fff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f0a1f420d2766c8b8d533c001668706a1a91802beb6c1e6a96bd9cf960b8c2e031858fb1f7be2e70e39d9f5fe8443de253f7e09b71b64646d6846ee47d5180f
|
7
|
+
data.tar.gz: 9e05b7594976c7113c9643b2f29546724dd4751c2a464d728de7440c5d578f1ceae6eb957dc2adc7325f857706fe44f5eebb70e2ef7085feb7076e0e44edb2e5
|
data/CHANGELOG.md
CHANGED
@@ -1,399 +1,262 @@
|
|
1
|
-
## Rails 7.
|
1
|
+
## Rails 7.1.2 (November 10, 2023) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails 7.
|
6
|
+
## Rails 7.1.1 (October 11, 2023) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails 7.0
|
11
|
+
## Rails 7.1.0 (October 05, 2023) ##
|
12
12
|
|
13
13
|
* No changes.
|
14
14
|
|
15
15
|
|
16
|
-
## Rails 7.0.
|
17
|
-
|
18
|
-
* Fix retrieving rotation value from FFmpeg on version 5.0+.
|
19
|
-
|
20
|
-
In FFmpeg version 5.0+ the rotation value has been removed from tags.
|
21
|
-
Instead the value can be found in side_data_list. Along with
|
22
|
-
this update it's possible to have values of -90, -270 to denote the video
|
23
|
-
has been rotated.
|
24
|
-
|
25
|
-
*Haroon Ahmed*
|
26
|
-
|
27
|
-
|
28
|
-
## Rails 7.0.5.1 (June 26, 2023) ##
|
29
|
-
|
30
|
-
* No changes.
|
31
|
-
|
32
|
-
|
33
|
-
## Rails 7.0.5 (May 24, 2023) ##
|
34
|
-
|
35
|
-
* No changes.
|
36
|
-
|
37
|
-
|
38
|
-
## Rails 7.0.4.3 (March 13, 2023) ##
|
39
|
-
|
40
|
-
* No changes.
|
41
|
-
|
42
|
-
|
43
|
-
## Rails 7.0.4.2 (January 24, 2023) ##
|
44
|
-
|
45
|
-
* No changes.
|
46
|
-
|
47
|
-
|
48
|
-
## Rails 7.0.4.1 (January 17, 2023) ##
|
49
|
-
|
50
|
-
* No changes.
|
51
|
-
|
52
|
-
|
53
|
-
## Rails 7.0.4 (September 09, 2022) ##
|
54
|
-
|
55
|
-
* Fixes proxy downloads of files over 5MiB
|
56
|
-
|
57
|
-
Previously, trying to view and/or download files larger than 5mb stored in
|
58
|
-
services like S3 via proxy mode could return corrupted files at around
|
59
|
-
5.2mb or cause random halts in the download. Now,
|
60
|
-
`ActiveStorage::Blobs::ProxyController` correctly handles streaming these
|
61
|
-
larger files from the service to the client without any issues.
|
62
|
-
|
63
|
-
Fixes #44679
|
64
|
-
|
65
|
-
*Felipe Raul*
|
66
|
-
|
67
|
-
## Rails 7.0.3.1 (July 12, 2022) ##
|
68
|
-
|
69
|
-
* No changes.
|
70
|
-
|
71
|
-
|
72
|
-
## Rails 7.0.3 (May 09, 2022) ##
|
73
|
-
|
74
|
-
* Don't stream responses in redirect mode
|
75
|
-
|
76
|
-
Previously, both redirect mode and proxy mode streamed their
|
77
|
-
responses which caused a new thread to be created, and could end
|
78
|
-
up leaking connections in the connection pool. But since redirect
|
79
|
-
mode doesn't actually send any data, it doesn't need to be
|
80
|
-
streamed.
|
81
|
-
|
82
|
-
*Luke Lau*
|
83
|
-
|
84
|
-
## Rails 7.0.2.4 (April 26, 2022) ##
|
85
|
-
|
86
|
-
* No changes.
|
87
|
-
|
88
|
-
|
89
|
-
## Rails 7.0.2.3 (March 08, 2022) ##
|
90
|
-
|
91
|
-
* Added image transformation validation via configurable allow-list.
|
92
|
-
|
93
|
-
Variant now offers a configurable allow-list for
|
94
|
-
transformation methods in addition to a configurable deny-list for arguments.
|
95
|
-
|
96
|
-
[CVE-2022-21831]
|
97
|
-
|
98
|
-
|
99
|
-
## Rails 7.0.2.2 (February 11, 2022) ##
|
16
|
+
## Rails 7.1.0.rc2 (October 01, 2023) ##
|
100
17
|
|
101
18
|
* No changes.
|
102
19
|
|
103
|
-
## Rails 7.0.2.1 (February 11, 2022) ##
|
104
|
-
|
105
|
-
* No changes.
|
106
|
-
|
107
|
-
|
108
|
-
## Rails 7.0.2 (February 08, 2022) ##
|
109
|
-
|
110
|
-
* Revert the ability to pass `service_name` param to `DirectUploadsController` which was introduced
|
111
|
-
in 7.0.0.
|
112
|
-
|
113
|
-
That change caused a lot of problems to upgrade Rails applications so we decided to remove it
|
114
|
-
while in work in a more backwards compatible implementation.
|
115
|
-
|
116
|
-
*Gannon McGibbon*
|
117
20
|
|
118
|
-
|
21
|
+
## Rails 7.1.0.rc1 (September 27, 2023) ##
|
119
22
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
## Rails 7.0.1 (January 06, 2022) ##
|
124
|
-
|
125
|
-
* No changes.
|
126
|
-
|
127
|
-
|
128
|
-
## Rails 7.0.0 (December 15, 2021) ##
|
129
|
-
|
130
|
-
* Support transforming empty-ish `has_many_attached` value into `[]` (e.g. `[""]`).
|
23
|
+
* Add `expires_at` option to `ActiveStorage::Blob#signed_id`.
|
131
24
|
|
132
25
|
```ruby
|
133
|
-
|
134
|
-
|
26
|
+
rails_blob_path(user.avatar, disposition: "attachment", expires_at: 30.minutes.from_now)
|
27
|
+
<%= image_tag rails_blob_path(user.avatar.variant(resize: "100x100"), expires_at: 30.minutes.from_now) %>
|
135
28
|
```
|
136
29
|
|
137
|
-
*
|
138
|
-
|
30
|
+
*Aki*
|
139
31
|
|
140
|
-
|
141
|
-
|
142
|
-
* No changes.
|
32
|
+
* Allow attaching File and Pathname when assigning attributes, e.g.
|
143
33
|
|
34
|
+
```ruby
|
35
|
+
User.create!(avatar: File.open("image.jpg"))
|
36
|
+
User.create!(avatar: file_fixture("image.jpg"))
|
37
|
+
```
|
144
38
|
|
145
|
-
|
146
|
-
|
147
|
-
* No changes.
|
148
|
-
|
149
|
-
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
150
|
-
|
151
|
-
* `Add ActiveStorage::Blob.compose` to concatenate multiple blobs.
|
152
|
-
|
153
|
-
*Gannon McGibbon*
|
154
|
-
|
155
|
-
* Setting custom metadata on blobs are now persisted to remote storage.
|
156
|
-
|
157
|
-
*joshuamsager*
|
158
|
-
|
159
|
-
* Support direct uploads to multiple services.
|
39
|
+
*Dorian Marié*
|
160
40
|
|
161
|
-
*Dmitry Tsepelev*
|
162
41
|
|
163
|
-
|
42
|
+
## Rails 7.1.0.beta1 (September 13, 2023) ##
|
164
43
|
|
165
|
-
|
166
|
-
|
44
|
+
* Disables the session in `ActiveStorage::Blobs::ProxyController`
|
45
|
+
and `ActiveStorage::Representations::ProxyController`
|
46
|
+
in order to allow caching by default in some CDNs as CloudFlare
|
167
47
|
|
168
|
-
|
48
|
+
Fixes #44136
|
169
49
|
|
170
|
-
|
50
|
+
*Bruno Prieto*
|
171
51
|
|
172
|
-
|
52
|
+
* Add `tags` to `ActiveStorage::Analyzer::AudioAnalyzer` output
|
173
53
|
|
174
|
-
|
54
|
+
*Keaton Roux*
|
175
55
|
|
176
|
-
*
|
56
|
+
* Add an option to preprocess variants
|
177
57
|
|
58
|
+
ActiveStorage variants are processed on the fly when they are needed but
|
59
|
+
sometimes we're sure that they are accessed and want to processed them
|
60
|
+
upfront.
|
178
61
|
|
179
|
-
|
62
|
+
`preprocessed` option is added when declaring variants.
|
180
63
|
|
181
|
-
|
182
|
-
|
183
|
-
|
64
|
+
```
|
65
|
+
class User < ApplicationRecord
|
66
|
+
has_one_attached :avatar do |attachable|
|
67
|
+
attachable.variant :thumb, resize_to_limit: [100, 100], preprocessed: true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
184
71
|
|
185
72
|
*Shouichi Kamiya*
|
186
73
|
|
187
|
-
*
|
188
|
-
|
189
|
-
*Tom Prats*
|
190
|
-
|
191
|
-
* Attachments can be deleted after their association is no longer defined.
|
192
|
-
|
193
|
-
Fixes #42514
|
194
|
-
|
195
|
-
*Don Sisco*
|
74
|
+
* Fix variants not included when eager loading multiple records containing a single attachment
|
196
75
|
|
197
|
-
|
76
|
+
When using the `with_attached_#{name}` scope for a `has_one_attached` relation,
|
77
|
+
attachment variants were not eagerly loaded.
|
198
78
|
|
199
|
-
|
200
|
-
not deprecated, existing apps can keep using it.
|
79
|
+
*Russell Porter*
|
201
80
|
|
202
|
-
|
81
|
+
* Allow an ActiveStorage attachment to be removed via a form post
|
203
82
|
|
204
|
-
|
205
|
-
|
83
|
+
Attachments can already be removed by updating the attachment to be nil such as:
|
84
|
+
```ruby
|
85
|
+
User.find(params[:id]).update!(avatar: nil)
|
86
|
+
```
|
206
87
|
|
207
|
-
|
88
|
+
However, a form cannot post a nil param, it can only post an empty string. But, posting an
|
89
|
+
empty string would result in an `ActiveSupport::MessageVerifier::InvalidSignature: mismatched digest`
|
90
|
+
error being raised, because it's being treated as a signed blob id.
|
208
91
|
|
209
|
-
|
92
|
+
Now, nil and an empty string are treated as a delete, which allows attachments to be removed via:
|
93
|
+
```ruby
|
94
|
+
User.find(params[:id]).update!(params.require(:user).permit(:avatar))
|
210
95
|
|
211
|
-
```yaml
|
212
|
-
gcs:
|
213
|
-
service: GCS
|
214
|
-
...
|
215
|
-
iam: true
|
216
96
|
```
|
217
97
|
|
218
|
-
*
|
219
|
-
|
220
|
-
* OpenSSL constants are now used for Digest computations.
|
98
|
+
*Nate Matykiewicz*
|
221
99
|
|
222
|
-
|
100
|
+
* Remove mini_mime usage in favour of marcel.
|
223
101
|
|
224
|
-
|
225
|
-
|
102
|
+
We have two libraries that are have similar usage. This change removes
|
103
|
+
dependency on mini_mime and makes use of similar methods from marcel.
|
226
104
|
|
227
|
-
*
|
105
|
+
*Vipul A M*
|
228
106
|
|
229
|
-
*
|
230
|
-
and `service_url` in favor of `url`.
|
107
|
+
* Allow destroying active storage variants
|
231
108
|
|
232
|
-
|
109
|
+
```ruby
|
110
|
+
User.first.avatar.variant(resize_to_limit: [100, 100]).destroy
|
111
|
+
```
|
233
112
|
|
234
|
-
*
|
113
|
+
*Shouichi Kamiya*, *Yuichiro NAKAGAWA*, *Ryohei UEDA*
|
235
114
|
|
236
|
-
|
115
|
+
* Add `sample_rate` to `ActiveStorage::Analyzer::AudioAnalyzer` output
|
237
116
|
|
238
|
-
*
|
117
|
+
*Matija Čupić*
|
239
118
|
|
240
|
-
|
119
|
+
* Remove deprecated `purge` and `purge_later` methods from the attachments association.
|
241
120
|
|
242
|
-
*
|
121
|
+
*Rafael Mendonça França*
|
243
122
|
|
244
|
-
|
123
|
+
* Remove deprecated behavior when assigning to a collection of attachments.
|
245
124
|
|
246
|
-
|
125
|
+
Instead of appending to the collection, the collection is now replaced.
|
247
126
|
|
248
|
-
|
249
|
-
`true` if the file has an video channel and `false` if it doesn't.
|
127
|
+
*Rafael Mendonça França*
|
250
128
|
|
251
|
-
|
129
|
+
* Remove deprecated `ActiveStorage::Current#host` and `ActiveStorage::Current#host=` methods.
|
252
130
|
|
253
|
-
*
|
131
|
+
*Rafael Mendonça França*
|
254
132
|
|
255
|
-
|
133
|
+
* Remove deprecated invalid default content types in Active Storage configurations.
|
256
134
|
|
257
|
-
*
|
135
|
+
*Rafael Mendonça França*
|
258
136
|
|
259
|
-
|
260
|
-
the S3 Presigner, enabling, amongst other options, custom S3 domain URL
|
261
|
-
Generation.
|
137
|
+
* Add missing preview event to `ActiveStorage::LogSubscriber`
|
262
138
|
|
263
|
-
|
264
|
-
|
139
|
+
A `preview` event is being instrumented in `ActiveStorage::Previewer`.
|
140
|
+
However it was not added inside ActiveStorage's LogSubscriber class.
|
265
141
|
|
266
|
-
|
267
|
-
|
268
|
-
|
142
|
+
This will allow to have logs for when a preview happens
|
143
|
+
in the same fashion as all other ActiveStorage events such as
|
144
|
+
`upload` and `download` inside `Rails.logger`.
|
269
145
|
|
270
|
-
*
|
146
|
+
*Chedli Bourguiba*
|
271
147
|
|
272
|
-
*
|
273
|
-
|
274
|
-
```yaml
|
275
|
-
gcs:
|
276
|
-
service: GCS
|
277
|
-
...
|
278
|
-
cache_control: "public, max-age=3600"
|
279
|
-
```
|
148
|
+
* Fix retrieving rotation value from FFmpeg on version 5.0+.
|
280
149
|
|
281
|
-
|
150
|
+
In FFmpeg version 5.0+ the rotation value has been removed from tags.
|
151
|
+
Instead the value can be found in side_data_list. Along with
|
152
|
+
this update it's possible to have values of -90, -270 to denote the video
|
153
|
+
has been rotated.
|
282
154
|
|
283
|
-
*
|
284
|
-
configurable under `config.active_storage.video_preview_arguments`.
|
155
|
+
*Haroon Ahmed*
|
285
156
|
|
286
|
-
|
157
|
+
* Touch all corresponding model records after ActiveStorage::Blob is analyzed
|
287
158
|
|
288
|
-
|
289
|
-
|
290
|
-
|
159
|
+
This fixes a race condition where a record can be requested and have a cache entry built, before
|
160
|
+
the initial `analyze_later` completes, which will not be invalidated until something else
|
161
|
+
updates the record. This also invalidates cache entries when a blob is re-analyzed, which
|
162
|
+
is helpful if a bug is fixed in an analyzer or a new analyzer is added.
|
291
163
|
|
292
|
-
*
|
164
|
+
*Nate Matykiewicz*
|
293
165
|
|
294
|
-
* Add
|
166
|
+
* Add ability to use pre-defined variants when calling `preview` or
|
167
|
+
`representation` on an attachment.
|
295
168
|
|
296
169
|
```ruby
|
297
|
-
|
170
|
+
class User < ActiveRecord::Base
|
171
|
+
has_one_attached :file do |attachable|
|
172
|
+
attachable.variant :thumb, resize_to_limit: [100, 100]
|
173
|
+
end
|
174
|
+
end
|
298
175
|
|
299
|
-
<%= image_tag
|
176
|
+
<%= image_tag user.file.representation(:thumb) %>
|
300
177
|
```
|
301
178
|
|
302
|
-
|
303
|
-
|
304
|
-
*aki77*
|
305
|
-
|
306
|
-
* Allow to purge an attachment when record is not persisted for `has_many_attached`.
|
307
|
-
|
308
|
-
*Jacopo Beschi*
|
309
|
-
|
310
|
-
* Add `with_all_variant_records` method to eager load all variant records on an attachment at once.
|
311
|
-
`with_attached_image` scope now eager loads variant records if using variant tracking.
|
312
|
-
|
313
|
-
*Alex Ghiculescu*
|
314
|
-
|
315
|
-
* Add metadata value for presence of audio channel in video blobs.
|
316
|
-
|
317
|
-
The `metadata` attribute of video blobs has a new boolean key named `audio` that is set to
|
318
|
-
`true` if the file has an audio channel and `false` if it doesn't.
|
319
|
-
|
320
|
-
*Breno Gazzola*
|
321
|
-
|
322
|
-
* Adds analyzer for audio files.
|
323
|
-
|
324
|
-
*Breno Gazzola*
|
179
|
+
*Richard Böhme*
|
325
180
|
|
326
|
-
*
|
181
|
+
* Method `attach` always returns the attachments except when the record
|
182
|
+
is persisted, unchanged, and saving it fails, in which case it returns `nil`.
|
327
183
|
|
328
|
-
*
|
184
|
+
*Santiago Bartesaghi*
|
329
185
|
|
330
|
-
*
|
186
|
+
* Fixes multiple `attach` calls within transaction not uploading files correctly.
|
331
187
|
|
332
|
-
|
188
|
+
In the following example, the code failed to upload all but the last file to the configured service.
|
189
|
+
```ruby
|
190
|
+
ActiveRecord::Base.transaction do
|
191
|
+
user.attachments.attach({
|
192
|
+
content_type: "text/plain",
|
193
|
+
filename: "dummy.txt",
|
194
|
+
io: ::StringIO.new("dummy"),
|
195
|
+
})
|
196
|
+
user.attachments.attach({
|
197
|
+
content_type: "text/plain",
|
198
|
+
filename: "dummy2.txt",
|
199
|
+
io: ::StringIO.new("dummy2"),
|
200
|
+
})
|
201
|
+
end
|
333
202
|
|
334
|
-
|
203
|
+
assert_equal 2, user.attachments.count
|
204
|
+
assert user.attachments.first.service.exist?(user.attachments.first.key) # Fails
|
205
|
+
```
|
335
206
|
|
336
|
-
|
207
|
+
This was addressed by keeping track of the subchanges pending upload, and uploading them
|
208
|
+
once the transaction is committed.
|
337
209
|
|
338
|
-
|
339
|
-
to allow for overriding aspects of the `ActiveStorage::VariantRecord` class. This makes
|
340
|
-
`ActiveStorage::VariantRecord` consistent with `ActiveStorage::Blob` and `ActiveStorage::Attachment`
|
341
|
-
that already have load hooks.
|
210
|
+
Fixes #41661
|
342
211
|
|
343
|
-
*
|
212
|
+
*Santiago Bartesaghi*, *Bruno Vezoli*, *Juan Roig*, *Abhay Nikam*
|
344
213
|
|
345
|
-
*
|
214
|
+
* Raise an exception if `config.active_storage.service` is not set.
|
346
215
|
|
347
|
-
|
216
|
+
If Active Storage is configured and `config.active_storage.service` is not
|
217
|
+
set in the respective environment's configuration file, then an exception
|
218
|
+
is raised with a meaningful message when attempting to use Active Storage.
|
348
219
|
|
349
|
-
*
|
350
|
-
which wraps the new `ActionController::Base#send_stream` method to stream a blob from cloud storage:
|
220
|
+
*Ghouse Mohamed*
|
351
221
|
|
352
|
-
|
353
|
-
class MyPublicBlobsController < ApplicationController
|
354
|
-
include ActiveStorage::SetBlob, ActiveStorage::Streaming
|
222
|
+
* Fixes proxy downloads of files over 5mb
|
355
223
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
end
|
362
|
-
```
|
224
|
+
Previously, trying to view and/or download files larger than 5mb stored in
|
225
|
+
services like S3 via proxy mode could return corrupted files at around
|
226
|
+
5.2mb or cause random halts in the download. Now,
|
227
|
+
`ActiveStorage::Blobs::ProxyController` correctly handles streaming these
|
228
|
+
larger files from the service to the client without any issues.
|
363
229
|
|
364
|
-
|
230
|
+
Fixes #44679
|
365
231
|
|
366
|
-
*
|
232
|
+
*Felipe Raul*
|
367
233
|
|
368
|
-
|
369
|
-
class User < ActiveRecord::Base
|
370
|
-
has_one_attached :avatar do |attachable|
|
371
|
-
attachable.variant :thumb, resize: "100x100"
|
372
|
-
attachable.variant :medium, resize: "300x300", monochrome: true
|
373
|
-
end
|
374
|
-
end
|
234
|
+
* Saving attachment(s) to a record returns the blob/blobs object
|
375
235
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
end
|
236
|
+
Previously, saving attachments did not return the blob/blobs that
|
237
|
+
were attached. Now, saving attachments to a record with `#attach`
|
238
|
+
method returns the blob or array of blobs that were attached to
|
239
|
+
the record. If it fails to save the attachment(s), then it returns
|
240
|
+
`false`.
|
382
241
|
|
383
|
-
|
384
|
-
```
|
242
|
+
*Ghouse Mohamed*
|
385
243
|
|
386
|
-
|
244
|
+
* Don't stream responses in redirect mode
|
387
245
|
|
388
|
-
|
389
|
-
|
246
|
+
Previously, both redirect mode and proxy mode streamed their
|
247
|
+
responses which caused a new thread to be created, and could end
|
248
|
+
up leaking connections in the connection pool. But since redirect
|
249
|
+
mode doesn't actually send any data, it doesn't need to be
|
250
|
+
streamed.
|
390
251
|
|
391
|
-
*
|
252
|
+
*Luke Lau*
|
392
253
|
|
393
|
-
*
|
394
|
-
improve fixture integration.
|
254
|
+
* Safe for direct upload on Libraries or Frameworks
|
395
255
|
|
396
|
-
|
256
|
+
Enable the use of custom headers during direct uploads, which allows for
|
257
|
+
the inclusion of Authorization bearer tokens or other forms of authorization
|
258
|
+
tokens through headers.
|
397
259
|
|
260
|
+
*Radamés Roriz*
|
398
261
|
|
399
|
-
Please check [
|
262
|
+
Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/activestorage/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -6,11 +6,11 @@ Files can be uploaded from the server to the cloud or directly from the client t
|
|
6
6
|
|
7
7
|
Image files can furthermore be transformed using on-demand variants for quality, aspect ratio, size, or any other [MiniMagick](https://github.com/minimagick/minimagick) or [Vips](https://www.rubydoc.info/gems/ruby-vips/Vips/Image) supported transformation.
|
8
8
|
|
9
|
-
You can read more about Active Storage in the [Active Storage Overview](https://
|
9
|
+
You can read more about Active Storage in the [Active Storage Overview](https://guides.rubyonrails.org/active_storage_overview.html) guide.
|
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/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`.
|
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
|
|
@@ -144,11 +144,11 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|
144
144
|
|
145
145
|
1. Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.
|
146
146
|
|
147
|
-
Requiring directly without bundling through the asset pipeline in the application
|
148
|
-
```
|
147
|
+
Requiring directly without bundling through the asset pipeline in the application HTML with autostart:
|
148
|
+
```erb
|
149
149
|
<%= javascript_include_tag "activestorage" %>
|
150
150
|
```
|
151
|
-
Requiring via importmap-rails without bundling through the asset pipeline in the application
|
151
|
+
Requiring via importmap-rails without bundling through the asset pipeline in the application HTML without autostart as ESM:
|
152
152
|
```ruby
|
153
153
|
# config/importmap.rb
|
154
154
|
pin "@rails/activestorage", to: "activestorage.esm.js"
|
@@ -170,7 +170,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|
170
170
|
```
|
171
171
|
2. Annotate file inputs with the direct upload URL.
|
172
172
|
|
173
|
-
```
|
173
|
+
```erb
|
174
174
|
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
|
175
175
|
```
|
176
176
|
3. That's it! Uploads begin upon form submission.
|
@@ -508,7 +508,7 @@ function toArray(value) {
|
|
508
508
|
}
|
509
509
|
|
510
510
|
class BlobRecord {
|
511
|
-
constructor(file, checksum, url) {
|
511
|
+
constructor(file, checksum, url, customHeaders = {}) {
|
512
512
|
this.file = file;
|
513
513
|
this.attributes = {
|
514
514
|
filename: file.name,
|
@@ -522,6 +522,9 @@ class BlobRecord {
|
|
522
522
|
this.xhr.setRequestHeader("Content-Type", "application/json");
|
523
523
|
this.xhr.setRequestHeader("Accept", "application/json");
|
524
524
|
this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
525
|
+
Object.keys(customHeaders).forEach((headerKey => {
|
526
|
+
this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]);
|
527
|
+
}));
|
525
528
|
const csrfToken = getMetaValue("csrf-token");
|
526
529
|
if (csrfToken != undefined) {
|
527
530
|
this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
@@ -604,11 +607,12 @@ class BlobUpload {
|
|
604
607
|
let id = 0;
|
605
608
|
|
606
609
|
class DirectUpload {
|
607
|
-
constructor(file, url, delegate) {
|
610
|
+
constructor(file, url, delegate, customHeaders = {}) {
|
608
611
|
this.id = ++id;
|
609
612
|
this.file = file;
|
610
613
|
this.url = url;
|
611
614
|
this.delegate = delegate;
|
615
|
+
this.customHeaders = customHeaders;
|
612
616
|
}
|
613
617
|
create(callback) {
|
614
618
|
FileChecksum.create(this.file, ((error, checksum) => {
|
@@ -616,7 +620,7 @@ class DirectUpload {
|
|
616
620
|
callback(error);
|
617
621
|
return;
|
618
622
|
}
|
619
|
-
const blob = new BlobRecord(this.file, checksum, this.url);
|
623
|
+
const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders);
|
620
624
|
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr);
|
621
625
|
blob.create((error => {
|
622
626
|
if (error) {
|
@@ -841,4 +845,4 @@ function autostart() {
|
|
841
845
|
|
842
846
|
setTimeout(autostart, 1);
|
843
847
|
|
844
|
-
export { DirectUpload, start };
|
848
|
+
export { DirectUpload, DirectUploadController, DirectUploadsController, start };
|