activestorage 8.0.5.2 → 8.1.0.beta1
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 +28 -279
- data/README.md +5 -2
- data/app/assets/javascripts/activestorage.esm.js +37 -1
- data/app/assets/javascripts/activestorage.js +37 -1
- data/app/controllers/active_storage/disk_controller.rb +0 -4
- data/app/controllers/concerns/active_storage/streaming.rb +5 -17
- data/app/javascript/activestorage/direct_upload_controller.js +48 -1
- data/app/models/active_storage/blob/representable.rb +2 -2
- data/app/models/active_storage/blob.rb +7 -48
- data/app/models/active_storage/filename.rb +5 -5
- data/app/models/active_storage/variant.rb +11 -11
- data/app/models/active_storage/variation.rb +1 -1
- data/lib/active_storage/analyzer/audio_analyzer.rb +0 -3
- data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +6 -14
- data/lib/active_storage/analyzer/image_analyzer/vips.rb +9 -12
- data/lib/active_storage/analyzer/image_analyzer.rb +5 -0
- data/lib/active_storage/analyzer/video_analyzer.rb +0 -3
- data/lib/active_storage/attached.rb +0 -1
- data/lib/active_storage/downloader.rb +1 -1
- data/lib/active_storage/engine.rb +41 -16
- data/lib/active_storage/errors.rb +0 -4
- data/lib/active_storage/gem_version.rb +3 -3
- data/lib/active_storage/previewer/video_previewer.rb +1 -1
- data/lib/active_storage/service/configurator.rb +6 -0
- data/lib/active_storage/service/disk_service.rb +3 -47
- data/lib/active_storage/service/gcs_service.rb +28 -13
- data/lib/active_storage/service/mirror_service.rb +1 -1
- data/lib/active_storage/service/registry.rb +6 -0
- data/lib/active_storage/service.rb +4 -1
- data/lib/active_storage/transformers/image_magick.rb +72 -0
- data/lib/active_storage/transformers/image_processing_transformer.rb +5 -67
- data/lib/active_storage/transformers/vips.rb +11 -0
- data/lib/active_storage.rb +4 -11
- metadata +15 -17
- data/lib/active_storage/image_magick/policy.xml +0 -68
- data/lib/active_storage/image_magick.rb +0 -63
- data/lib/active_storage/service/azure_storage_service.rb +0 -201
- data/lib/active_storage/vips.rb +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8959531cd3a50439e1d30882ac0398b7d361da8a6859049b01c31e1a35e58862
|
|
4
|
+
data.tar.gz: c4027f992ab9f941cecbe88a7a415d52f5a3800b86e69fe8789567f320a9b9ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2750ae72f60c4e388b74813b74fa2580a5ebe48887eca53905b1d1173a08bac4ff931f22fadc3fb2ffec0d96417f7661fe22aba44cdaa36e7480c7df4b0f52d0
|
|
7
|
+
data.tar.gz: 3201606c2dce4e6e41649c8aca6432dbd2c0635c966366809bc6552ad07cc074596d3d973054bce87f79f3eca9ffb68d91e116d9b8f81ac5dad7d59b8040cd5b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,254 +1,51 @@
|
|
|
1
|
-
## Rails 8.0.
|
|
1
|
+
## Rails 8.1.0.beta1 (September 04, 2025) ##
|
|
2
2
|
|
|
3
|
-
*
|
|
4
|
-
streamed download.
|
|
3
|
+
* Remove deprecated `:azure` storage service.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
*Rafael Mendonça França*
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Derive `ActiveStorage::Filename#base` and `#extension` from the sanitized
|
|
11
|
-
filename.
|
|
12
|
-
|
|
13
|
-
This prevents null bytes and invalid byte sequences in stored filename
|
|
14
|
-
metadata from raising when a blob is opened or represented. Existing blob
|
|
15
|
-
records are handled without a data migration.
|
|
16
|
-
|
|
17
|
-
[GHSA-p2pm-g2h6-7j5j]
|
|
18
|
-
|
|
19
|
-
*Jeremy Daer*
|
|
20
|
-
|
|
21
|
-
* Ship an ImageMagick security policy and apply it to every ImageMagick
|
|
22
|
-
process MiniMagick spawns.
|
|
23
|
-
|
|
24
|
-
ImageMagick chooses a coder from the content of the file it is given, and
|
|
25
|
-
some coders act on files named inside the image rather than on the image
|
|
26
|
-
itself. Active Storage constrained none of them, so an uploaded file could
|
|
27
|
-
reach any coder the host's policy allowed, through the ImageMagick analyzer
|
|
28
|
-
at attach time, with no variant or `analyze` call in the application.
|
|
29
|
-
|
|
30
|
-
Active Storage now ships a `policy.xml` in
|
|
31
|
-
`ActiveStorage::ImageMagick::POLICY_DIRECTORY` and prepends that directory
|
|
32
|
-
to `MAGICK_CONFIGURE_PATH` through `MiniMagick.cli_env`. ImageMagick applies
|
|
33
|
-
every policy file on its search path, so the shipped policy adds to the
|
|
34
|
-
host's policy rather than replacing it. A `MAGICK_CONFIGURE_PATH` set in the
|
|
35
|
-
environment or in `MiniMagick.cli_env`, including by an initializer or
|
|
36
|
-
dotenv, is kept after the shipped directory.
|
|
37
|
-
|
|
38
|
-
The shipped policy denies the coders that script ImageMagick (`MSL`), read
|
|
39
|
-
or delete files other than the image (`TEXT`, `EPHEMERAL`), fetch remote
|
|
40
|
-
references (`URL`, `HTTP`, `HTTPS`, `FTP`), display to a screen (`SHOW`,
|
|
41
|
-
`WIN`, `PLT`), or hand the file to Ghostscript (the `PS`, `EPS`, `EPT` and
|
|
42
|
-
`PDF` coders, every alias of them, and the `gs` delegate), or reach a file
|
|
43
|
-
directly (`FILE`, `MPC`, `XPS`, `PCL`), and it refuses `@filename`
|
|
44
|
-
indirection. The policy applies to every ImageMagick command MiniMagick
|
|
45
|
-
runs, not only Active Storage's.
|
|
46
|
-
|
|
47
|
-
These applications must act:
|
|
48
|
-
|
|
49
|
-
* One whose variant processor is `:mini_magick` has to use mini_magick 5.1
|
|
50
|
-
or later, which applying the policy requires. With an older mini_magick,
|
|
51
|
-
it raises at boot.
|
|
52
|
-
* One that renders PostScript or PDF through ImageMagick has to re-allow
|
|
53
|
-
the `gs` delegate and the coders it uses in the host's `policy.xml`. A
|
|
54
|
-
host policy that allows a coder overrides the shipped deny.
|
|
55
|
-
* One that replaces `MiniMagick.cli_env` after it boots, clears the
|
|
56
|
-
environment with `MiniMagick.cli_prefix`, or installs its own
|
|
57
|
-
`MiniMagick::Shell` never receives the shipped policy and has to carry
|
|
58
|
-
its rules in ImageMagick's system policy. So does one that uses
|
|
59
|
-
GraphicsMagick, which does not read ImageMagick policies.
|
|
60
|
-
|
|
61
|
-
Every other application needs no change. See "ImageMagick Security Policy"
|
|
62
|
-
in the Active Storage guide.
|
|
63
|
-
|
|
64
|
-
[GHSA-f3w6-w445-fwh9]
|
|
65
|
-
|
|
66
|
-
*Mike Dalessio*
|
|
67
|
-
|
|
68
|
-
* Enforce the declared content length on Google Cloud Storage direct uploads.
|
|
69
|
-
|
|
70
|
-
The signed URL now requires an `x-goog-content-length-range` header matching the blob's
|
|
71
|
-
`byte_size`, so Cloud Storage rejects a body of any other size.
|
|
72
|
-
|
|
73
|
-
Browsers send the new header, so a bucket's CORS configuration must list
|
|
74
|
-
`x-goog-content-length-range` in `responseHeader`, or direct uploads from the browser fail.
|
|
75
|
-
|
|
76
|
-
[GHSA-hfr4-8rjc-97m2]
|
|
77
|
-
|
|
78
|
-
*Mike Dalessio*
|
|
79
|
-
|
|
80
|
-
* Sign GCS direct uploads with V2 when `cache_control` is set.
|
|
81
|
-
|
|
82
|
-
V4 signatures did not bind the Content-Type or Content-MD5 headers, so the uploader could
|
|
83
|
-
choose the stored Content-Type. Direct-upload URLs with `cache_control` are no longer limited
|
|
84
|
-
to 7 days, and the client sends `Cache-Control` unsigned.
|
|
85
|
-
|
|
86
|
-
[GHSA-3w93-6hmw-whh4]
|
|
87
|
-
|
|
88
|
-
*Mike Dalessio*
|
|
89
|
-
|
|
90
|
-
* Stop an uploaded filename choosing the extension of the tempfile Active
|
|
91
|
-
Storage hands to an external tool.
|
|
7
|
+
* Remove unnecessary calls to the GCP metadata server.
|
|
92
8
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[GHSA-v924-7rp8-4mxh]
|
|
100
|
-
|
|
101
|
-
*Mike Dalessio*
|
|
102
|
-
|
|
103
|
-
* Restrict the formats ffmpeg and ffprobe will open when previewing and
|
|
104
|
-
analyzing video and audio.
|
|
105
|
-
|
|
106
|
-
Active Storage now passes `-format_whitelist` before the input at every
|
|
107
|
-
ffmpeg and ffprobe call site, limiting demuxer selection to common audio and
|
|
108
|
-
video container formats. Configure the list with
|
|
109
|
-
`config.active_storage.ffmpeg_allowed_formats`, or set it to `nil` to let
|
|
110
|
-
ffmpeg choose any demuxer it was built with.
|
|
111
|
-
|
|
112
|
-
Files in other formats, such as MXF, DV, AC3, WavPack, AU, W64, and raw
|
|
113
|
-
H.264 or MPEG-1/2 video streams, now fail to preview with
|
|
114
|
-
`ActiveStorage::PreviewError`, and their analysis stores no media metadata
|
|
115
|
-
and logs a warning. Add their demuxers to the list to keep them.
|
|
9
|
+
Calling Google::Auth.get_application_default triggers an explicit call to
|
|
10
|
+
the metadata server - given it was being called for significant number of
|
|
11
|
+
file operations, it can lead to considerable tail latencies and even metadata
|
|
12
|
+
server overloads. Instead, it's preferable (and significantly more efficient)
|
|
13
|
+
that applications use:
|
|
116
14
|
|
|
117
15
|
```ruby
|
|
118
|
-
|
|
16
|
+
Google::Apis::RequestOptions.default.authorization = Google::Auth.get_application_default(...)
|
|
119
17
|
```
|
|
120
18
|
|
|
121
|
-
|
|
19
|
+
In the cases applications do not set that, the GCP libraries automatically determine credentials.
|
|
122
20
|
|
|
123
|
-
|
|
21
|
+
This also enables using credentials other than those of the associated GCP
|
|
22
|
+
service account like when using impersonation.
|
|
124
23
|
|
|
125
|
-
|
|
24
|
+
*Alex Coomans*
|
|
126
25
|
|
|
127
|
-
*
|
|
26
|
+
* Direct upload progress accounts for server processing time.
|
|
128
27
|
|
|
129
|
-
|
|
130
|
-
safe for trusted content. Active Storage will call `Vips.block_untrusted(true)` to disable them
|
|
131
|
-
while booting. An application that needs a specific loader or saver may re-enable it in an
|
|
132
|
-
initializer.
|
|
28
|
+
*Jeremy Daer*
|
|
133
29
|
|
|
134
|
-
|
|
135
|
-
saver. Variant transformation of BMP, ICO, and PSD attachments will raise `Vips::Error`, and
|
|
136
|
-
analysis of these and other types such as SVG, JPEG XL, JPEG 2000, and Netpbm will no longer
|
|
137
|
-
record `width` and `height`. Requesting an unfuzzed output format, typically FITS, JXL, or
|
|
138
|
-
anything delegated to ImageMagick, will also raise `Vips::Error`. Attaching, storing, and
|
|
139
|
-
downloading are unchanged.
|
|
30
|
+
* Delegate `ActiveStorage::Filename#to_str` to `#to_s`
|
|
140
31
|
|
|
141
|
-
|
|
142
|
-
affected content types from `config.active_storage.variable_content_types` in an initializer.
|
|
143
|
-
Active Storage will then treat those attachments as not variable and will not generate variants
|
|
144
|
-
for them. This most often matters to an application that transforms images during a request
|
|
145
|
-
rather than in a background job, where the failure surfaces as an error response instead of a
|
|
146
|
-
failed job.
|
|
32
|
+
Supports checking String equality:
|
|
147
33
|
|
|
148
34
|
```ruby
|
|
149
|
-
|
|
150
|
-
|
|
35
|
+
filename = ActiveStorage::Filename.new("file.txt")
|
|
36
|
+
filename == "file.txt" # => true
|
|
37
|
+
filename in "file.txt" # => true
|
|
38
|
+
"file.txt" == filename # => true
|
|
151
39
|
```
|
|
152
40
|
|
|
153
|
-
|
|
154
|
-
attachments are processed, but the loaders and savers will be disabled process-wide whenever
|
|
155
|
-
ruby-vips is installed, and the version requirements below will still apply. Such an application
|
|
156
|
-
may remove ruby-vips from its Gemfile to avoid both.
|
|
157
|
-
|
|
158
|
-
The minimum supported version of libvips is now 8.13, and the minimum supported version of
|
|
159
|
-
ruby-vips is now 2.2.1. These are the earliest versions that are capable of disabling untrusted
|
|
160
|
-
operations. When ruby-vips is installed and either minimum is not met, Active Storage will raise
|
|
161
|
-
a `RuntimeError` while booting rather than run in an unsecurable environment.
|
|
162
|
-
|
|
163
|
-
[GHSA-xr9x-r78c-5hrm]
|
|
164
|
-
[CVE-2026-66066]
|
|
165
|
-
|
|
166
|
-
*Mike Dalessio*
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
## Rails 8.0.5 (March 24, 2026) ##
|
|
170
|
-
|
|
171
|
-
* Fix `ActiveStorage::Blob` content type predicate methods to handle `nil`.
|
|
172
|
-
|
|
173
|
-
*Daichi KUDO*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
## Rails 8.0.4.1 (March 23, 2026) ##
|
|
177
|
-
|
|
178
|
-
* Filter user supplied metadata in DirectUploadController
|
|
179
|
-
|
|
180
|
-
[CVE-2026-33173]
|
|
181
|
-
|
|
182
|
-
*Jean Boussier*
|
|
183
|
-
|
|
184
|
-
* Configurable maxmimum streaming chunk size
|
|
185
|
-
|
|
186
|
-
Makes sure that byte ranges for blobs don't exceed 100mb by default.
|
|
187
|
-
Content ranges that are too big can result in denial of service.
|
|
188
|
-
|
|
189
|
-
[CVE-2026-33174]
|
|
190
|
-
|
|
191
|
-
*Gannon McGibbon*
|
|
192
|
-
|
|
193
|
-
* Limit range requests to a single range
|
|
194
|
-
|
|
195
|
-
[CVE-2026-33658]
|
|
196
|
-
|
|
197
|
-
*Jean Boussier*
|
|
41
|
+
*Sean Doyle*
|
|
198
42
|
|
|
199
|
-
*
|
|
43
|
+
* Add support for alternative MD5 implementation through `config.active_storage.checksum_implementation`.
|
|
200
44
|
|
|
201
|
-
|
|
202
|
-
|
|
45
|
+
Also automatically degrade to using the slower `Digest::MD5` implementation if `OpenSSL::Digest::MD5`
|
|
46
|
+
is found to be disabled because of OpenSSL FIPS mode.
|
|
203
47
|
|
|
204
|
-
|
|
205
|
-
example containing null bytes or having an incompatible encoding. Previously, the exception
|
|
206
|
-
raised may have been `ArgumentError` or `Encoding::CompatibilityError`.
|
|
207
|
-
|
|
208
|
-
`DiskController` now explicitly rescues `InvalidKeyError` with appropriate HTTP status codes.
|
|
209
|
-
|
|
210
|
-
[CVE-2026-33195]
|
|
211
|
-
|
|
212
|
-
*Mike Dalessio*
|
|
213
|
-
|
|
214
|
-
* Prevent glob injection in `DiskService#delete_prefixed`.
|
|
215
|
-
|
|
216
|
-
Escape glob metacharacters in the resolved path before passing to `Dir.glob`.
|
|
217
|
-
|
|
218
|
-
Note that this change breaks any existing code that is relying on `delete_prefixed` to expand
|
|
219
|
-
glob metacharacters. This change presumes that is unintended behavior (as other storage services
|
|
220
|
-
do not respect these metacharacters).
|
|
221
|
-
|
|
222
|
-
[CVE-2026-33202]
|
|
223
|
-
|
|
224
|
-
*Mike Dalessio*
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
## Rails 8.0.4 (October 28, 2025) ##
|
|
228
|
-
|
|
229
|
-
* No changes.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
## Rails 8.0.3 (September 22, 2025) ##
|
|
233
|
-
|
|
234
|
-
* Address deprecation of `Aws::S3::Object#upload_stream` in `ActiveStorage::Service::S3Service`.
|
|
235
|
-
|
|
236
|
-
*Joshua Young*
|
|
237
|
-
|
|
238
|
-
* Fix `config.active_storage.touch_attachment_records` to work with eager loading.
|
|
239
|
-
|
|
240
|
-
*fatkodima*
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
## Rails 8.0.2.1 (August 13, 2025) ##
|
|
244
|
-
|
|
245
|
-
* Remove dangerous transformations
|
|
246
|
-
|
|
247
|
-
[CVE-2025-24293]
|
|
248
|
-
|
|
249
|
-
*Zack Deveau*
|
|
250
|
-
|
|
251
|
-
## Rails 8.0.2 (March 12, 2025) ##
|
|
48
|
+
*Matt Pasquini*, *Jean Boussier*
|
|
252
49
|
|
|
253
50
|
* A Blob will no longer autosave associated Attachment.
|
|
254
51
|
|
|
@@ -262,52 +59,4 @@
|
|
|
262
59
|
|
|
263
60
|
*Edouard-chin*
|
|
264
61
|
|
|
265
|
-
|
|
266
|
-
## Rails 8.0.1 (December 13, 2024) ##
|
|
267
|
-
|
|
268
|
-
* No changes.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
## Rails 8.0.0.1 (December 10, 2024) ##
|
|
272
|
-
|
|
273
|
-
* No changes.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
## Rails 8.0.0 (November 07, 2024) ##
|
|
277
|
-
|
|
278
|
-
* No changes.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
## Rails 8.0.0.rc2 (October 30, 2024) ##
|
|
282
|
-
|
|
283
|
-
* No changes.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
## Rails 8.0.0.rc1 (October 19, 2024) ##
|
|
287
|
-
|
|
288
|
-
* No changes.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
## Rails 8.0.0.beta1 (September 26, 2024) ##
|
|
292
|
-
|
|
293
|
-
* Deprecate `ActiveStorage::Service::AzureStorageService`.
|
|
294
|
-
|
|
295
|
-
*zzak*
|
|
296
|
-
|
|
297
|
-
* Improve `ActiveStorage::Filename#sanitized` method to handle special characters more effectively.
|
|
298
|
-
Replace the characters `"*?<>` with `-` if they exist in the Filename to match the Filename convention of Win OS.
|
|
299
|
-
|
|
300
|
-
*Luong Viet Dung(Martin)*
|
|
301
|
-
|
|
302
|
-
* Improve InvariableError, UnpreviewableError and UnrepresentableError message.
|
|
303
|
-
|
|
304
|
-
Include Blob ID and content_type in the messages.
|
|
305
|
-
|
|
306
|
-
*Petrik de Heus*
|
|
307
|
-
|
|
308
|
-
* Mark proxied files as `immutable` in their Cache-Control header
|
|
309
|
-
|
|
310
|
-
*Nate Matykiewicz*
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activestorage/CHANGELOG.md) for previous changes.
|
|
62
|
+
Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/activestorage/CHANGELOG.md) for previous changes.
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Active Storage
|
|
2
2
|
|
|
3
|
-
Active Storage makes it simple to upload and reference files in cloud services like [Amazon S3](https://aws.amazon.com/s3/), [Google Cloud Storage](https://cloud.google.com/storage/docs/),
|
|
3
|
+
Active Storage makes it simple to upload and reference files in cloud services like [Amazon S3](https://aws.amazon.com/s3/), or [Google Cloud Storage](https://cloud.google.com/storage/docs/), and attach those files to Active Records. Supports having one main service and mirrors in other services for redundancy. It also provides a disk service for testing or local deployments, but the focus is on cloud storage.
|
|
4
4
|
|
|
5
5
|
Files can be uploaded from the server to the cloud or directly from the client to the cloud.
|
|
6
6
|
|
|
@@ -173,7 +173,10 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|
|
173
173
|
```erb
|
|
174
174
|
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
|
|
175
175
|
```
|
|
176
|
-
|
|
176
|
+
|
|
177
|
+
3. Configure CORS on third-party storage services to allow direct upload requests.
|
|
178
|
+
|
|
179
|
+
4. That's it! Uploads begin upon form submission.
|
|
177
180
|
|
|
178
181
|
### Direct upload JavaScript events
|
|
179
182
|
|
|
@@ -672,7 +672,7 @@ class DirectUploadController {
|
|
|
672
672
|
}));
|
|
673
673
|
}
|
|
674
674
|
uploadRequestDidProgress(event) {
|
|
675
|
-
const progress = event.loaded / event.total *
|
|
675
|
+
const progress = event.loaded / event.total * 90;
|
|
676
676
|
if (progress) {
|
|
677
677
|
this.dispatch("progress", {
|
|
678
678
|
progress: progress
|
|
@@ -707,6 +707,42 @@ class DirectUploadController {
|
|
|
707
707
|
xhr: xhr
|
|
708
708
|
});
|
|
709
709
|
xhr.upload.addEventListener("progress", (event => this.uploadRequestDidProgress(event)));
|
|
710
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
711
|
+
this.simulateResponseProgress(xhr);
|
|
712
|
+
}));
|
|
713
|
+
}
|
|
714
|
+
simulateResponseProgress(xhr) {
|
|
715
|
+
let progress = 90;
|
|
716
|
+
const startTime = Date.now();
|
|
717
|
+
const updateProgress = () => {
|
|
718
|
+
const elapsed = Date.now() - startTime;
|
|
719
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
720
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
721
|
+
progress = 90 + responseProgress * 9;
|
|
722
|
+
this.dispatch("progress", {
|
|
723
|
+
progress: progress
|
|
724
|
+
});
|
|
725
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
726
|
+
requestAnimationFrame(updateProgress);
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
xhr.addEventListener("loadend", (() => {
|
|
730
|
+
this.dispatch("progress", {
|
|
731
|
+
progress: 100
|
|
732
|
+
});
|
|
733
|
+
}));
|
|
734
|
+
requestAnimationFrame(updateProgress);
|
|
735
|
+
}
|
|
736
|
+
estimateResponseTime() {
|
|
737
|
+
const fileSize = this.file.size;
|
|
738
|
+
const MB = 1024 * 1024;
|
|
739
|
+
if (fileSize < MB) {
|
|
740
|
+
return 1e3;
|
|
741
|
+
} else if (fileSize < 10 * MB) {
|
|
742
|
+
return 2e3;
|
|
743
|
+
} else {
|
|
744
|
+
return 3e3 + fileSize / MB * 50;
|
|
745
|
+
}
|
|
710
746
|
}
|
|
711
747
|
}
|
|
712
748
|
|
|
@@ -662,7 +662,7 @@
|
|
|
662
662
|
}));
|
|
663
663
|
}
|
|
664
664
|
uploadRequestDidProgress(event) {
|
|
665
|
-
const progress = event.loaded / event.total *
|
|
665
|
+
const progress = event.loaded / event.total * 90;
|
|
666
666
|
if (progress) {
|
|
667
667
|
this.dispatch("progress", {
|
|
668
668
|
progress: progress
|
|
@@ -697,6 +697,42 @@
|
|
|
697
697
|
xhr: xhr
|
|
698
698
|
});
|
|
699
699
|
xhr.upload.addEventListener("progress", (event => this.uploadRequestDidProgress(event)));
|
|
700
|
+
xhr.upload.addEventListener("loadend", (() => {
|
|
701
|
+
this.simulateResponseProgress(xhr);
|
|
702
|
+
}));
|
|
703
|
+
}
|
|
704
|
+
simulateResponseProgress(xhr) {
|
|
705
|
+
let progress = 90;
|
|
706
|
+
const startTime = Date.now();
|
|
707
|
+
const updateProgress = () => {
|
|
708
|
+
const elapsed = Date.now() - startTime;
|
|
709
|
+
const estimatedResponseTime = this.estimateResponseTime();
|
|
710
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1);
|
|
711
|
+
progress = 90 + responseProgress * 9;
|
|
712
|
+
this.dispatch("progress", {
|
|
713
|
+
progress: progress
|
|
714
|
+
});
|
|
715
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
716
|
+
requestAnimationFrame(updateProgress);
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
xhr.addEventListener("loadend", (() => {
|
|
720
|
+
this.dispatch("progress", {
|
|
721
|
+
progress: 100
|
|
722
|
+
});
|
|
723
|
+
}));
|
|
724
|
+
requestAnimationFrame(updateProgress);
|
|
725
|
+
}
|
|
726
|
+
estimateResponseTime() {
|
|
727
|
+
const fileSize = this.file.size;
|
|
728
|
+
const MB = 1024 * 1024;
|
|
729
|
+
if (fileSize < MB) {
|
|
730
|
+
return 1e3;
|
|
731
|
+
} else if (fileSize < 10 * MB) {
|
|
732
|
+
return 2e3;
|
|
733
|
+
} else {
|
|
734
|
+
return 3e3 + fileSize / MB * 50;
|
|
735
|
+
}
|
|
700
736
|
}
|
|
701
737
|
}
|
|
702
738
|
const inputSelector = "input[type=file][data-direct-upload-url]:not([disabled])";
|
|
@@ -17,8 +17,6 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
|
|
|
17
17
|
end
|
|
18
18
|
rescue Errno::ENOENT
|
|
19
19
|
head :not_found
|
|
20
|
-
rescue ActiveStorage::InvalidKeyError
|
|
21
|
-
head :not_found
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
def update
|
|
@@ -34,8 +32,6 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
|
|
|
34
32
|
end
|
|
35
33
|
rescue ActiveStorage::IntegrityError
|
|
36
34
|
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
|
|
37
|
-
rescue ActiveStorage::InvalidKeyError
|
|
38
|
-
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
|
|
39
35
|
end
|
|
40
36
|
|
|
41
37
|
private
|
|
@@ -14,8 +14,7 @@ module ActiveStorage::Streaming
|
|
|
14
14
|
def send_blob_byte_range_data(blob, range_header, disposition: nil)
|
|
15
15
|
ranges = Rack::Utils.get_byte_ranges(range_header, blob.byte_size)
|
|
16
16
|
|
|
17
|
-
return head(:range_not_satisfiable)
|
|
18
|
-
return head(:range_not_satisfiable) if ranges.length > ActiveStorage.streaming_max_ranges
|
|
17
|
+
return head(:range_not_satisfiable) if ranges.blank? || ranges.all?(&:blank?)
|
|
19
18
|
|
|
20
19
|
if ranges.length == 1
|
|
21
20
|
range = ranges.first
|
|
@@ -52,12 +51,6 @@ module ActiveStorage::Streaming
|
|
|
52
51
|
)
|
|
53
52
|
end
|
|
54
53
|
|
|
55
|
-
def ranges_valid?(ranges)
|
|
56
|
-
return false if ranges.blank? || ranges.all?(&:blank?)
|
|
57
|
-
|
|
58
|
-
ranges.sum { |range| range.end - range.begin } < ActiveStorage.streaming_chunk_max_size
|
|
59
|
-
end
|
|
60
|
-
|
|
61
54
|
# Stream the blob from storage directly to the response. The disposition can be controlled by setting +disposition+.
|
|
62
55
|
# The content type and filename is set directly from the +blob+.
|
|
63
56
|
def send_blob_stream(blob, disposition: nil) # :doc:
|
|
@@ -69,18 +62,13 @@ module ActiveStorage::Streaming
|
|
|
69
62
|
stream.write chunk
|
|
70
63
|
end
|
|
71
64
|
rescue ActiveStorage::FileNotFoundError
|
|
72
|
-
raise if response.committed?
|
|
73
|
-
|
|
74
65
|
expires_now
|
|
75
66
|
head :not_found
|
|
76
67
|
rescue
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
head :internal_server_error
|
|
82
|
-
end
|
|
83
|
-
|
|
68
|
+
# Status and caching headers are already set, but not committed.
|
|
69
|
+
# Change the status to 500 manually.
|
|
70
|
+
expires_now
|
|
71
|
+
head :internal_server_error
|
|
84
72
|
raise
|
|
85
73
|
end
|
|
86
74
|
end
|
|
@@ -31,7 +31,8 @@ export class DirectUploadController {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
uploadRequestDidProgress(event) {
|
|
34
|
-
|
|
34
|
+
// Scale upload progress to 0-90% range
|
|
35
|
+
const progress = (event.loaded / event.total) * 90
|
|
35
36
|
if (progress) {
|
|
36
37
|
this.dispatch("progress", { progress })
|
|
37
38
|
}
|
|
@@ -63,5 +64,51 @@ export class DirectUploadController {
|
|
|
63
64
|
directUploadWillStoreFileWithXHR(xhr) {
|
|
64
65
|
this.dispatch("before-storage-request", { xhr })
|
|
65
66
|
xhr.upload.addEventListener("progress", event => this.uploadRequestDidProgress(event))
|
|
67
|
+
|
|
68
|
+
// Start simulating progress after upload completes
|
|
69
|
+
xhr.upload.addEventListener("loadend", () => {
|
|
70
|
+
this.simulateResponseProgress(xhr)
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
simulateResponseProgress(xhr) {
|
|
75
|
+
let progress = 90
|
|
76
|
+
const startTime = Date.now()
|
|
77
|
+
|
|
78
|
+
const updateProgress = () => {
|
|
79
|
+
// Simulate progress from 90% to 99% over estimated time
|
|
80
|
+
const elapsed = Date.now() - startTime
|
|
81
|
+
const estimatedResponseTime = this.estimateResponseTime()
|
|
82
|
+
const responseProgress = Math.min(elapsed / estimatedResponseTime, 1)
|
|
83
|
+
progress = 90 + (responseProgress * 9) // 90% to 99%
|
|
84
|
+
|
|
85
|
+
this.dispatch("progress", { progress })
|
|
86
|
+
|
|
87
|
+
// Continue until response arrives or we hit 99%
|
|
88
|
+
if (xhr.readyState !== XMLHttpRequest.DONE && progress < 99) {
|
|
89
|
+
requestAnimationFrame(updateProgress)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Stop simulation when response arrives
|
|
94
|
+
xhr.addEventListener("loadend", () => {
|
|
95
|
+
this.dispatch("progress", { progress: 100 })
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
requestAnimationFrame(updateProgress)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
estimateResponseTime() {
|
|
102
|
+
// Base estimate: 1 second for small files, scaling up for larger files
|
|
103
|
+
const fileSize = this.file.size
|
|
104
|
+
const MB = 1024 * 1024
|
|
105
|
+
|
|
106
|
+
if (fileSize < MB) {
|
|
107
|
+
return 1000 // 1 second for files under 1MB
|
|
108
|
+
} else if (fileSize < 10 * MB) {
|
|
109
|
+
return 2000 // 2 seconds for files 1-10MB
|
|
110
|
+
} else {
|
|
111
|
+
return 3000 + (fileSize / MB * 50) // 3+ seconds for larger files
|
|
112
|
+
}
|
|
66
113
|
}
|
|
67
114
|
}
|
|
@@ -25,8 +25,8 @@ module ActiveStorage::Blob::Representable
|
|
|
25
25
|
#
|
|
26
26
|
# <%= image_tag Current.user.avatar.variant(resize_to_limit: [100, 100]) %>
|
|
27
27
|
#
|
|
28
|
-
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::
|
|
29
|
-
#
|
|
28
|
+
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::RepresentationsController
|
|
29
|
+
# can then produce on-demand.
|
|
30
30
|
#
|
|
31
31
|
# Raises ActiveStorage::InvariableError if the variant processor cannot
|
|
32
32
|
# transform the blob. To determine whether a blob is variable, call
|