activestorage 6.1.7 → 7.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +152 -276
- data/MIT-LICENSE +1 -1
- data/README.md +29 -15
- data/app/assets/javascripts/activestorage.esm.js +848 -0
- data/app/assets/javascripts/activestorage.js +263 -376
- data/app/controllers/active_storage/base_controller.rb +0 -9
- data/app/controllers/active_storage/blobs/proxy_controller.rb +16 -4
- data/app/controllers/active_storage/blobs/redirect_controller.rb +6 -4
- data/app/controllers/active_storage/disk_controller.rb +5 -2
- data/app/controllers/active_storage/representations/base_controller.rb +5 -1
- data/app/controllers/active_storage/representations/proxy_controller.rb +8 -3
- data/app/controllers/active_storage/representations/redirect_controller.rb +6 -4
- data/app/controllers/concerns/active_storage/disable_session.rb +12 -0
- data/app/controllers/concerns/active_storage/file_server.rb +4 -1
- data/app/controllers/concerns/active_storage/set_blob.rb +6 -2
- data/app/controllers/concerns/active_storage/set_current.rb +3 -3
- data/app/controllers/concerns/active_storage/streaming.rb +66 -0
- 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/javascript/activestorage/ujs.js +1 -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 +111 -4
- 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 +14 -8
- data/app/models/active_storage/blob.rb +93 -57
- data/app/models/active_storage/current.rb +2 -2
- 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 +11 -7
- data/app/models/active_storage/record.rb +1 -1
- data/app/models/active_storage/variant.rb +10 -12
- data/app/models/active_storage/variant_record.rb +2 -0
- data/app/models/active_storage/variant_with_record.rb +28 -12
- data/app/models/active_storage/variation.rb +7 -5
- data/config/routes.rb +12 -10
- data/db/migrate/20170806125915_create_active_storage_tables.rb +15 -6
- data/db/update_migrate/20211119233751_remove_not_null_on_active_storage_blobs_checksum.rb +7 -0
- data/lib/active_storage/analyzer/audio_analyzer.rb +77 -0
- data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +41 -0
- data/lib/active_storage/analyzer/image_analyzer/vips.rb +51 -0
- data/lib/active_storage/analyzer/image_analyzer.rb +4 -30
- data/lib/active_storage/analyzer/video_analyzer.rb +41 -17
- data/lib/active_storage/analyzer.rb +10 -4
- data/lib/active_storage/attached/changes/create_many.rb +14 -5
- data/lib/active_storage/attached/changes/create_one.rb +46 -4
- data/lib/active_storage/attached/changes/create_one_of_many.rb +1 -1
- data/lib/active_storage/attached/changes/delete_many.rb +1 -1
- data/lib/active_storage/attached/changes/delete_one.rb +1 -1
- data/lib/active_storage/attached/changes/detach_many.rb +18 -0
- data/lib/active_storage/attached/changes/detach_one.rb +24 -0
- data/lib/active_storage/attached/changes/purge_many.rb +27 -0
- data/lib/active_storage/attached/changes/purge_one.rb +27 -0
- data/lib/active_storage/attached/changes.rb +7 -1
- data/lib/active_storage/attached/many.rb +32 -19
- data/lib/active_storage/attached/model.rb +80 -29
- data/lib/active_storage/attached/one.rb +37 -31
- data/lib/active_storage/attached.rb +2 -0
- data/lib/active_storage/deprecator.rb +7 -0
- data/lib/active_storage/downloader.rb +4 -4
- data/lib/active_storage/engine.rb +55 -7
- data/lib/active_storage/fixture_set.rb +75 -0
- data/lib/active_storage/gem_version.rb +3 -3
- data/lib/active_storage/log_subscriber.rb +12 -0
- data/lib/active_storage/previewer.rb +12 -5
- data/lib/active_storage/reflection.rb +12 -2
- data/lib/active_storage/service/azure_storage_service.rb +30 -6
- data/lib/active_storage/service/configurator.rb +1 -1
- data/lib/active_storage/service/disk_service.rb +26 -19
- data/lib/active_storage/service/gcs_service.rb +100 -11
- data/lib/active_storage/service/mirror_service.rb +12 -7
- data/lib/active_storage/service/registry.rb +1 -1
- data/lib/active_storage/service/s3_service.rb +39 -15
- data/lib/active_storage/service.rb +17 -7
- data/lib/active_storage/transformers/image_processing_transformer.rb +1 -1
- data/lib/active_storage/transformers/transformer.rb +3 -1
- data/lib/active_storage/version.rb +1 -1
- data/lib/active_storage.rb +22 -2
- metadata +30 -30
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f09e751b9896e3e99bda5b07a2f946e14cc08a8b25b29b872c85d918fa906c1
|
4
|
+
data.tar.gz: f10ad7fbf13f79f91b690a6417a7f035038f62f2c82ee39a94070566773c2bd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5fc945abbfdfbe05b6aeafa393ef6b6995fa1c0e6f908006dc52e570ba9d17e982f40df652814b95e5da0db68a7bacf8f0a7820de2bec928fbaf1519fed00bd
|
7
|
+
data.tar.gz: 627a0bf0f41c633ce7f3c098b264ffafebe6d081b2aea39ef0c9e30985fe06fb167b192abfd5fd5d729cef9592abe2acade5760ea792089373482dce1183b867
|
data/CHANGELOG.md
CHANGED
@@ -1,376 +1,252 @@
|
|
1
|
-
## Rails
|
2
|
-
|
3
|
-
* Respect Active Record's primary_key_type in Active Storage migrations. Backported from 7.0.
|
4
|
-
|
5
|
-
*fatkodima*
|
6
|
-
|
7
|
-
## Rails 6.1.6.1 (July 12, 2022) ##
|
8
|
-
|
9
|
-
* No changes.
|
10
|
-
|
11
|
-
|
12
|
-
## Rails 6.1.6 (May 09, 2022) ##
|
1
|
+
## Rails 7.1.0 (October 05, 2023) ##
|
13
2
|
|
14
3
|
* No changes.
|
15
4
|
|
16
5
|
|
17
|
-
## Rails
|
6
|
+
## Rails 7.1.0.rc2 (October 01, 2023) ##
|
18
7
|
|
19
8
|
* No changes.
|
20
9
|
|
21
10
|
|
22
|
-
## Rails
|
23
|
-
|
24
|
-
* Attachments can be deleted after their association is no longer defined.
|
25
|
-
|
26
|
-
Fixes #42514
|
27
|
-
|
28
|
-
*Don Sisco*
|
29
|
-
|
30
|
-
|
31
|
-
## Rails 6.1.4.7 (March 08, 2022) ##
|
32
|
-
|
33
|
-
* Added image transformation validation via configurable allow-list.
|
34
|
-
|
35
|
-
Variant now offers a configurable allow-list for
|
36
|
-
transformation methods in addition to a configurable deny-list for arguments.
|
37
|
-
|
38
|
-
[CVE-2022-21831]
|
39
|
-
|
40
|
-
|
41
|
-
## Rails 6.1.4.6 (February 11, 2022) ##
|
42
|
-
|
43
|
-
* No changes.
|
44
|
-
|
45
|
-
|
46
|
-
## Rails 6.1.4.5 (February 11, 2022) ##
|
47
|
-
|
48
|
-
* No changes.
|
49
|
-
|
50
|
-
|
51
|
-
## Rails 6.1.4.4 (December 15, 2021) ##
|
52
|
-
|
53
|
-
* No changes.
|
54
|
-
|
55
|
-
|
56
|
-
## Rails 6.1.4.3 (December 14, 2021) ##
|
57
|
-
|
58
|
-
* No changes.
|
11
|
+
## Rails 7.1.0.rc1 (September 27, 2023) ##
|
59
12
|
|
13
|
+
* Add `expires_at` option to `ActiveStorage::Blob#signed_id`.
|
60
14
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
## Rails 6.1.4.1 (August 19, 2021) ##
|
67
|
-
|
68
|
-
* No changes.
|
69
|
-
|
70
|
-
|
71
|
-
## Rails 6.1.4 (June 24, 2021) ##
|
72
|
-
|
73
|
-
* The parameters sent to `ffmpeg` for generating a video preview image are now
|
74
|
-
configurable under `config.active_storage.video_preview_arguments`.
|
75
|
-
|
76
|
-
*Brendon Muir*
|
15
|
+
```ruby
|
16
|
+
rails_blob_path(user.avatar, disposition: "attachment", expires_at: 30.minutes.from_now)
|
17
|
+
<%= image_tag rails_blob_path(user.avatar.variant(resize: "100x100"), expires_at: 30.minutes.from_now) %>
|
18
|
+
```
|
77
19
|
|
78
|
-
*
|
20
|
+
*Aki*
|
79
21
|
|
80
|
-
|
22
|
+
* Allow attaching File and Pathname when assigning attributes, e.g.
|
81
23
|
|
82
|
-
|
24
|
+
```ruby
|
25
|
+
User.create!(avatar: File.open("image.jpg"))
|
26
|
+
User.create!(avatar: file_fixture("image.jpg"))
|
27
|
+
```
|
83
28
|
|
84
|
-
|
29
|
+
*Dorian Marié*
|
85
30
|
|
86
|
-
*Alex Ghiculescu*
|
87
31
|
|
88
|
-
|
32
|
+
## Rails 7.1.0.beta1 (September 13, 2023) ##
|
89
33
|
|
90
|
-
|
34
|
+
* Disables the session in `ActiveStorage::Blobs::ProxyController`
|
35
|
+
and `ActiveStorage::Representations::ProxyController`
|
36
|
+
in order to allow caching by default in some CDNs as CloudFlare
|
91
37
|
|
92
|
-
|
38
|
+
Fixes #44136
|
93
39
|
|
94
|
-
*
|
40
|
+
*Bruno Prieto*
|
95
41
|
|
96
|
-
* `
|
42
|
+
* Add `tags` to `ActiveStorage::Analyzer::AudioAnalyzer` output
|
97
43
|
|
98
|
-
*
|
44
|
+
*Keaton Roux*
|
99
45
|
|
46
|
+
* Add an option to preprocess variants
|
100
47
|
|
101
|
-
|
48
|
+
ActiveStorage variants are processed on the fly when they are needed but
|
49
|
+
sometimes we're sure that they are accessed and want to processed them
|
50
|
+
upfront.
|
102
51
|
|
103
|
-
|
52
|
+
`preprocessed` option is added when declaring variants.
|
104
53
|
|
54
|
+
```
|
55
|
+
class User < ApplicationRecord
|
56
|
+
has_one_attached :avatar do |attachable|
|
57
|
+
attachable.variant :thumb, resize_to_limit: [100, 100], preprocessed: true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
105
61
|
|
106
|
-
|
62
|
+
*Shouichi Kamiya*
|
107
63
|
|
108
|
-
*
|
109
|
-
mime types data.
|
64
|
+
* Fix variants not included when eager loading multiple records containing a single attachment
|
110
65
|
|
111
|
-
|
66
|
+
When using the `with_attached_#{name}` scope for a `has_one_attached` relation,
|
67
|
+
attachment variants were not eagerly loaded.
|
112
68
|
|
69
|
+
*Russell Porter*
|
113
70
|
|
114
|
-
|
71
|
+
* Allow an ActiveStorage attachment to be removed via a form post
|
115
72
|
|
116
|
-
|
73
|
+
Attachments can already be removed by updating the attachment to be nil such as:
|
74
|
+
```ruby
|
75
|
+
User.find(params[:id]).update!(avatar: nil)
|
76
|
+
```
|
117
77
|
|
78
|
+
However, a form cannot post a nil param, it can only post an empty string. But, posting an
|
79
|
+
empty string would result in an `ActiveSupport::MessageVerifier::InvalidSignature: mismatched digest`
|
80
|
+
error being raised, because it's being treated as a signed blob id.
|
118
81
|
|
119
|
-
|
82
|
+
Now, nil and an empty string are treated as a delete, which allows attachments to be removed via:
|
83
|
+
```ruby
|
84
|
+
User.find(params[:id]).update!(params.require(:user).permit(:avatar))
|
120
85
|
|
121
|
-
|
86
|
+
```
|
122
87
|
|
88
|
+
*Nate Matykiewicz*
|
123
89
|
|
124
|
-
|
90
|
+
* Remove mini_mime usage in favour of marcel.
|
125
91
|
|
126
|
-
|
92
|
+
We have two libraries that are have similar usage. This change removes
|
93
|
+
dependency on mini_mime and makes use of similar methods from marcel.
|
127
94
|
|
95
|
+
*Vipul A M*
|
128
96
|
|
129
|
-
|
97
|
+
* Allow destroying active storage variants
|
130
98
|
|
131
|
-
|
99
|
+
```ruby
|
100
|
+
User.first.avatar.variant(resize_to_limit: [100, 100]).destroy
|
101
|
+
```
|
132
102
|
|
133
|
-
*
|
103
|
+
*Shouichi Kamiya*, *Yuichiro NAKAGAWA*, *Ryohei UEDA*
|
134
104
|
|
105
|
+
* Add `sample_rate` to `ActiveStorage::Analyzer::AudioAnalyzer` output
|
135
106
|
|
136
|
-
|
107
|
+
*Matija Čupić*
|
137
108
|
|
138
|
-
*
|
139
|
-
purge (`:active_storage_purge`) jobs to be the job adapter's default (`:default`).
|
109
|
+
* Remove deprecated `purge` and `purge_later` methods from the attachments association.
|
140
110
|
|
141
111
|
*Rafael Mendonça França*
|
142
112
|
|
143
|
-
*
|
113
|
+
* Remove deprecated behavior when assigning to a collection of attachments.
|
144
114
|
|
145
|
-
|
146
|
-
|
147
|
-
* Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing`.
|
115
|
+
Instead of appending to the collection, the collection is now replaced.
|
148
116
|
|
149
117
|
*Rafael Mendonça França*
|
150
118
|
|
151
|
-
* Remove deprecated `ActiveStorage::
|
119
|
+
* Remove deprecated `ActiveStorage::Current#host` and `ActiveStorage::Current#host=` methods.
|
152
120
|
|
153
121
|
*Rafael Mendonça França*
|
154
122
|
|
155
|
-
* Remove deprecated
|
123
|
+
* Remove deprecated invalid default content types in Active Storage configurations.
|
156
124
|
|
157
125
|
*Rafael Mendonça França*
|
158
126
|
|
159
|
-
*
|
127
|
+
* Add missing preview event to `ActiveStorage::LogSubscriber`
|
160
128
|
|
161
|
-
|
129
|
+
A `preview` event is being instrumented in `ActiveStorage::Previewer`.
|
130
|
+
However it was not added inside ActiveStorage's LogSubscriber class.
|
162
131
|
|
163
|
-
|
132
|
+
This will allow to have logs for when a preview happens
|
133
|
+
in the same fashion as all other ActiveStorage events such as
|
134
|
+
`upload` and `download` inside `Rails.logger`.
|
164
135
|
|
165
|
-
*
|
136
|
+
*Chedli Bourguiba*
|
166
137
|
|
167
|
-
*
|
168
|
-
document's crop box rather than its media box, hiding print margins. This
|
169
|
-
matches the behavior of the MuPDF previewer.
|
138
|
+
* Fix retrieving rotation value from FFmpeg on version 5.0+.
|
170
139
|
|
171
|
-
|
140
|
+
In FFmpeg version 5.0+ the rotation value has been removed from tags.
|
141
|
+
Instead the value can be found in side_data_list. Along with
|
142
|
+
this update it's possible to have values of -90, -270 to denote the video
|
143
|
+
has been rotated.
|
172
144
|
|
173
|
-
*
|
145
|
+
*Haroon Ahmed*
|
174
146
|
|
175
|
-
|
147
|
+
* Touch all corresponding model records after ActiveStorage::Blob is analyzed
|
176
148
|
|
177
|
-
|
178
|
-
|
179
|
-
|
149
|
+
This fixes a race condition where a record can be requested and have a cache entry built, before
|
150
|
+
the initial `analyze_later` completes, which will not be invalidated until something else
|
151
|
+
updates the record. This also invalidates cache entries when a blob is re-analyzed, which
|
152
|
+
is helpful if a bug is fixed in an analyzer or a new analyzer is added.
|
180
153
|
|
181
|
-
|
182
|
-
<%= image_tag rails_storage_proxy_path(@user.avatar) %>
|
183
|
-
```
|
154
|
+
*Nate Matykiewicz*
|
184
155
|
|
185
|
-
|
156
|
+
* Add ability to use pre-defined variants when calling `preview` or
|
157
|
+
`representation` on an attachment.
|
186
158
|
|
187
159
|
```ruby
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
<%= image_tag @user.avatar %>
|
194
|
-
```
|
195
|
-
|
196
|
-
To redirect to a signed service URL when the default file serving strategy
|
197
|
-
is set to proxying, use the `rails_storage_redirect_path` and `_url` helpers:
|
160
|
+
class User < ActiveRecord::Base
|
161
|
+
has_one_attached :file do |attachable|
|
162
|
+
attachable.variant :thumb, resize_to_limit: [100, 100]
|
163
|
+
end
|
164
|
+
end
|
198
165
|
|
199
|
-
|
200
|
-
<%= image_tag rails_storage_redirect_path(@user.avatar) %>
|
166
|
+
<%= image_tag user.file.representation(:thumb) %>
|
201
167
|
```
|
202
168
|
|
203
|
-
*
|
204
|
-
|
205
|
-
* Add `config.active_storage.web_image_content_types` to allow applications
|
206
|
-
to add content types (like `image/webp`) in which variants can be processed,
|
207
|
-
instead of letting those images be converted to the fallback PNG format.
|
208
|
-
|
209
|
-
*Jeroen van Haperen*
|
210
|
-
|
211
|
-
* Add support for creating variants of `WebP` images out of the box.
|
212
|
-
|
213
|
-
*Dino Maric*
|
214
|
-
|
215
|
-
* Only enqueue analysis jobs for blobs with non-null analyzer classes.
|
216
|
-
|
217
|
-
*Gannon McGibbon*
|
218
|
-
|
219
|
-
* Previews are created on the same service as the original blob.
|
220
|
-
|
221
|
-
*Peter Zhu*
|
222
|
-
|
223
|
-
* Remove unused `disposition` and `content_type` query parameters for `DiskService`.
|
224
|
-
|
225
|
-
*Peter Zhu*
|
226
|
-
|
227
|
-
* Use `DiskController` for both public and private files.
|
228
|
-
|
229
|
-
`DiskController` is able to handle multiple services by adding a
|
230
|
-
`service_name` field in the generated URL in `DiskService`.
|
231
|
-
|
232
|
-
*Peter Zhu*
|
233
|
-
|
234
|
-
* Variants are tracked in the database to avoid existence checks in the storage service.
|
235
|
-
|
236
|
-
*George Claghorn*
|
237
|
-
|
238
|
-
* Deprecate `service_url` methods in favour of `url`.
|
239
|
-
|
240
|
-
Deprecate `Variant#service_url` and `Preview#service_url` to instead use
|
241
|
-
`#url` method to be consistent with `Blob`.
|
242
|
-
|
243
|
-
*Peter Zhu*
|
244
|
-
|
245
|
-
* Permanent URLs for public storage blobs.
|
246
|
-
|
247
|
-
Services can be configured in `config/storage.yml` with a new key
|
248
|
-
`public: true | false` to indicate whether a service holds public
|
249
|
-
blobs or private blobs. Public services will always return a permanent URL.
|
169
|
+
*Richard Böhme*
|
250
170
|
|
251
|
-
|
171
|
+
* Method `attach` always returns the attachments except when the record
|
172
|
+
is persisted, unchanged, and saving it fails, in which case it returns `nil`.
|
252
173
|
|
253
|
-
*
|
174
|
+
*Santiago Bartesaghi*
|
254
175
|
|
255
|
-
*
|
256
|
-
|
257
|
-
*Gannon McGibbon*
|
258
|
-
|
259
|
-
* The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
|
260
|
-
|
261
|
-
*Kyle Ribordy*
|
262
|
-
|
263
|
-
* Allow storage services to be configured per attachment.
|
176
|
+
* Fixes multiple `attach` calls within transaction not uploading files correctly.
|
264
177
|
|
178
|
+
In the following example, the code failed to upload all but the last file to the configured service.
|
265
179
|
```ruby
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
180
|
+
ActiveRecord::Base.transaction do
|
181
|
+
user.attachments.attach({
|
182
|
+
content_type: "text/plain",
|
183
|
+
filename: "dummy.txt",
|
184
|
+
io: ::StringIO.new("dummy"),
|
185
|
+
})
|
186
|
+
user.attachments.attach({
|
187
|
+
content_type: "text/plain",
|
188
|
+
filename: "dummy2.txt",
|
189
|
+
io: ::StringIO.new("dummy2"),
|
190
|
+
})
|
272
191
|
end
|
273
|
-
```
|
274
|
-
|
275
|
-
*Dmitry Tsepelev*
|
276
192
|
|
277
|
-
|
278
|
-
|
279
|
-
```ruby
|
280
|
-
user.avatar.attach key: "avatars/#{user.id}.jpg",
|
281
|
-
io: io, content_type: "image/jpeg", filename: "avatar.jpg"
|
193
|
+
assert_equal 2, user.attachments.count
|
194
|
+
assert user.attachments.first.service.exist?(user.attachments.first.key) # Fails
|
282
195
|
```
|
283
196
|
|
284
|
-
|
285
|
-
|
286
|
-
*George Claghorn*
|
287
|
-
|
288
|
-
* Replace `Blob.create_after_upload!` with `Blob.create_and_upload!` and deprecate the former.
|
289
|
-
|
290
|
-
`create_after_upload!` has been removed since it could lead to data
|
291
|
-
corruption by uploading to a key on the storage service which happened to
|
292
|
-
be already taken. Creating the record would then correctly raise a
|
293
|
-
database uniqueness exception but the stored object would already have
|
294
|
-
overwritten another. `create_and_upload!` swaps the order of operations
|
295
|
-
so that the key gets reserved up-front or the uniqueness error gets raised,
|
296
|
-
before the upload to a key takes place.
|
197
|
+
This was addressed by keeping track of the subchanges pending upload, and uploading them
|
198
|
+
once the transaction is committed.
|
297
199
|
|
298
|
-
|
200
|
+
Fixes #41661
|
299
201
|
|
300
|
-
*
|
202
|
+
*Santiago Bartesaghi*, *Bruno Vezoli*, *Juan Roig*, *Abhay Nikam*
|
301
203
|
|
302
|
-
|
204
|
+
* Raise an exception if `config.active_storage.service` is not set.
|
303
205
|
|
304
|
-
|
305
|
-
|
206
|
+
If Active Storage is configured and `config.active_storage.service` is not
|
207
|
+
set in the respective environment's configuration file, then an exception
|
208
|
+
is raised with a meaningful message when attempting to use Active Storage.
|
306
209
|
|
307
|
-
*
|
210
|
+
*Ghouse Mohamed*
|
308
211
|
|
309
|
-
*
|
212
|
+
* Fixes proxy downloads of files over 5mb
|
310
213
|
|
311
|
-
|
214
|
+
Previously, trying to view and/or download files larger than 5mb stored in
|
215
|
+
services like S3 via proxy mode could return corrupted files at around
|
216
|
+
5.2mb or cause random halts in the download. Now,
|
217
|
+
`ActiveStorage::Blobs::ProxyController` correctly handles streaming these
|
218
|
+
larger files from the service to the client without any issues.
|
312
219
|
|
313
|
-
|
220
|
+
Fixes #44679
|
314
221
|
|
315
|
-
*
|
222
|
+
*Felipe Raul*
|
316
223
|
|
317
|
-
*
|
224
|
+
* Saving attachment(s) to a record returns the blob/blobs object
|
318
225
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
226
|
+
Previously, saving attachments did not return the blob/blobs that
|
227
|
+
were attached. Now, saving attachments to a record with `#attach`
|
228
|
+
method returns the blob or array of blobs that were attached to
|
229
|
+
the record. If it fails to save the attachment(s), then it returns
|
230
|
+
`false`.
|
323
231
|
|
324
|
-
*
|
232
|
+
*Ghouse Mohamed*
|
325
233
|
|
326
|
-
*
|
234
|
+
* Don't stream responses in redirect mode
|
327
235
|
|
328
|
-
Previously,
|
329
|
-
|
236
|
+
Previously, both redirect mode and proxy mode streamed their
|
237
|
+
responses which caused a new thread to be created, and could end
|
238
|
+
up leaking connections in the connection pool. But since redirect
|
239
|
+
mode doesn't actually send any data, it doesn't need to be
|
240
|
+
streamed.
|
330
241
|
|
331
|
-
|
332
|
-
class User < ApplicationRecord
|
333
|
-
has_one_attached :avatar
|
334
|
-
end
|
335
|
-
```
|
336
|
-
|
337
|
-
They now return `nil`.
|
338
|
-
|
339
|
-
*Matthew Tanous*
|
340
|
-
|
341
|
-
* The mirror service supports direct uploads.
|
242
|
+
*Luke Lau*
|
342
243
|
|
343
|
-
|
344
|
-
directly-uploaded file is attached to a record, a background job is enqueued
|
345
|
-
to copy it to each secondary service.
|
346
|
-
|
347
|
-
Configure the queue used to process mirroring jobs by setting
|
348
|
-
`config.active_storage.queues.mirror`. The default is `:active_storage_mirror`.
|
349
|
-
|
350
|
-
*George Claghorn*
|
351
|
-
|
352
|
-
* The S3 service now permits uploading files larger than 5 gigabytes.
|
353
|
-
|
354
|
-
When uploading a file greater than 100 megabytes in size, the service
|
355
|
-
transparently switches to [multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html)
|
356
|
-
using a part size computed from the file's total size and S3's part count limit.
|
357
|
-
|
358
|
-
No application changes are necessary to take advantage of this feature. You
|
359
|
-
can customize the default 100 MB multipart upload threshold in your S3
|
360
|
-
service's configuration:
|
361
|
-
|
362
|
-
```yaml
|
363
|
-
production:
|
364
|
-
service: s3
|
365
|
-
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
366
|
-
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
367
|
-
region: us-east-1
|
368
|
-
bucket: my-bucket
|
369
|
-
upload:
|
370
|
-
multipart_threshold: <%= 250.megabytes %>
|
371
|
-
```
|
244
|
+
* Safe for direct upload on Libraries or Frameworks
|
372
245
|
|
373
|
-
|
246
|
+
Enable the use of custom headers during direct uploads, which allows for
|
247
|
+
the inclusion of Authorization bearer tokens or other forms of authorization
|
248
|
+
tokens through headers.
|
374
249
|
|
250
|
+
*Radamés Roriz*
|
375
251
|
|
376
|
-
Please check [
|
252
|
+
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
|
|
@@ -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/
|
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
|
-
|
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
|
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
|
+
```erb
|
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
|
@@ -156,7 +170,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|
156
170
|
```
|
157
171
|
2. Annotate file inputs with the direct upload URL.
|
158
172
|
|
159
|
-
```
|
173
|
+
```erb
|
160
174
|
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
|
161
175
|
```
|
162
176
|
3. That's it! Uploads begin upon form submission.
|
@@ -185,7 +199,7 @@ API documentation is at:
|
|
185
199
|
|
186
200
|
* https://api.rubyonrails.org
|
187
201
|
|
188
|
-
Bug reports for the Ruby on Rails project can be filed here:
|
202
|
+
Bug reports for the Ruby on \Rails project can be filed here:
|
189
203
|
|
190
204
|
* https://github.com/rails/rails/issues
|
191
205
|
|