-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActiveStorage.html
658 lines (394 loc) · 31.2 KB
/
ActiveStorage.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
---
title: ActiveStorage
layout: default
---
<div class="main">
<div class="banner">
<span>Ruby on Rails 8.0.0</span><br />
<div class="type">Module</div>
<h1>
ActiveStorage
</h1>
<ul class="files">
<li><a href="../files/activestorage/app/controllers/active_storage/base_controller_rb.html">activestorage/app/controllers/active_storage/base_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/blobs/proxy_controller_rb.html">activestorage/app/controllers/active_storage/blobs/proxy_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/blobs/redirect_controller_rb.html">activestorage/app/controllers/active_storage/blobs/redirect_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/direct_uploads_controller_rb.html">activestorage/app/controllers/active_storage/direct_uploads_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/disk_controller_rb.html">activestorage/app/controllers/active_storage/disk_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/representations/base_controller_rb.html">activestorage/app/controllers/active_storage/representations/base_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/representations/proxy_controller_rb.html">activestorage/app/controllers/active_storage/representations/proxy_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/active_storage/representations/redirect_controller_rb.html">activestorage/app/controllers/active_storage/representations/redirect_controller.rb</a></li>
<li><a href="../files/activestorage/app/controllers/concerns/active_storage/disable_session_rb.html">activestorage/app/controllers/concerns/active_storage/disable_session.rb</a></li>
<li><a href="../files/activestorage/app/controllers/concerns/active_storage/file_server_rb.html">activestorage/app/controllers/concerns/active_storage/file_server.rb</a></li>
<li><a href="../files/activestorage/app/controllers/concerns/active_storage/set_blob_rb.html">activestorage/app/controllers/concerns/active_storage/set_blob.rb</a></li>
<li><a href="../files/activestorage/app/controllers/concerns/active_storage/set_current_rb.html">activestorage/app/controllers/concerns/active_storage/set_current.rb</a></li>
<li><a href="../files/activestorage/app/controllers/concerns/active_storage/streaming_rb.html">activestorage/app/controllers/concerns/active_storage/streaming.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/analyze_job_rb.html">activestorage/app/jobs/active_storage/analyze_job.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/base_job_rb.html">activestorage/app/jobs/active_storage/base_job.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/mirror_job_rb.html">activestorage/app/jobs/active_storage/mirror_job.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/preview_image_job_rb.html">activestorage/app/jobs/active_storage/preview_image_job.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/purge_job_rb.html">activestorage/app/jobs/active_storage/purge_job.rb</a></li>
<li><a href="../files/activestorage/app/jobs/active_storage/transform_job_rb.html">activestorage/app/jobs/active_storage/transform_job.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/attachment_rb.html">activestorage/app/models/active_storage/attachment.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/blob_rb.html">activestorage/app/models/active_storage/blob.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/blob/analyzable_rb.html">activestorage/app/models/active_storage/blob/analyzable.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/blob/identifiable_rb.html">activestorage/app/models/active_storage/blob/identifiable.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/blob/representable_rb.html">activestorage/app/models/active_storage/blob/representable.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/blob/servable_rb.html">activestorage/app/models/active_storage/blob/servable.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/current_rb.html">activestorage/app/models/active_storage/current.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/filename_rb.html">activestorage/app/models/active_storage/filename.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/named_variant_rb.html">activestorage/app/models/active_storage/named_variant.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/preview_rb.html">activestorage/app/models/active_storage/preview.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/record_rb.html">activestorage/app/models/active_storage/record.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/variant_rb.html">activestorage/app/models/active_storage/variant.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/variant_record_rb.html">activestorage/app/models/active_storage/variant_record.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/variant_with_record_rb.html">activestorage/app/models/active_storage/variant_with_record.rb</a></li>
<li><a href="../files/activestorage/app/models/active_storage/variation_rb.html">activestorage/app/models/active_storage/variation.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage_rb.html">activestorage/lib/active_storage.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer_rb.html">activestorage/lib/active_storage/analyzer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/audio_analyzer_rb.html">activestorage/lib/active_storage/analyzer/audio_analyzer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/image_analyzer_rb.html">activestorage/lib/active_storage/analyzer/image_analyzer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/image_analyzer/image_magick_rb.html">activestorage/lib/active_storage/analyzer/image_analyzer/image_magick.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/image_analyzer/vips_rb.html">activestorage/lib/active_storage/analyzer/image_analyzer/vips.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/null_analyzer_rb.html">activestorage/lib/active_storage/analyzer/null_analyzer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/analyzer/video_analyzer_rb.html">activestorage/lib/active_storage/analyzer/video_analyzer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached_rb.html">activestorage/lib/active_storage/attached.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes_rb.html">activestorage/lib/active_storage/attached/changes.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/create_many_rb.html">activestorage/lib/active_storage/attached/changes/create_many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/create_one_rb.html">activestorage/lib/active_storage/attached/changes/create_one.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/create_one_of_many_rb.html">activestorage/lib/active_storage/attached/changes/create_one_of_many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/delete_many_rb.html">activestorage/lib/active_storage/attached/changes/delete_many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/delete_one_rb.html">activestorage/lib/active_storage/attached/changes/delete_one.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/detach_many_rb.html">activestorage/lib/active_storage/attached/changes/detach_many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/detach_one_rb.html">activestorage/lib/active_storage/attached/changes/detach_one.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/purge_many_rb.html">activestorage/lib/active_storage/attached/changes/purge_many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/changes/purge_one_rb.html">activestorage/lib/active_storage/attached/changes/purge_one.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/many_rb.html">activestorage/lib/active_storage/attached/many.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/model_rb.html">activestorage/lib/active_storage/attached/model.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/attached/one_rb.html">activestorage/lib/active_storage/attached/one.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/deprecator_rb.html">activestorage/lib/active_storage/deprecator.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/downloader_rb.html">activestorage/lib/active_storage/downloader.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/engine_rb.html">activestorage/lib/active_storage/engine.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/errors_rb.html">activestorage/lib/active_storage/errors.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/fixture_set_rb.html">activestorage/lib/active_storage/fixture_set.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/gem_version_rb.html">activestorage/lib/active_storage/gem_version.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/log_subscriber_rb.html">activestorage/lib/active_storage/log_subscriber.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/previewer_rb.html">activestorage/lib/active_storage/previewer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/previewer/mupdf_previewer_rb.html">activestorage/lib/active_storage/previewer/mupdf_previewer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/previewer/poppler_pdf_previewer_rb.html">activestorage/lib/active_storage/previewer/poppler_pdf_previewer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/previewer/video_previewer_rb.html">activestorage/lib/active_storage/previewer/video_previewer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/reflection_rb.html">activestorage/lib/active_storage/reflection.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service_rb.html">activestorage/lib/active_storage/service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/azure_storage_service_rb.html">activestorage/lib/active_storage/service/azure_storage_service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/configurator_rb.html">activestorage/lib/active_storage/service/configurator.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/disk_service_rb.html">activestorage/lib/active_storage/service/disk_service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/gcs_service_rb.html">activestorage/lib/active_storage/service/gcs_service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/mirror_service_rb.html">activestorage/lib/active_storage/service/mirror_service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/registry_rb.html">activestorage/lib/active_storage/service/registry.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/service/s3_service_rb.html">activestorage/lib/active_storage/service/s3_service.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/transformers/image_processing_transformer_rb.html">activestorage/lib/active_storage/transformers/image_processing_transformer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/transformers/transformer_rb.html">activestorage/lib/active_storage/transformers/transformer.rb</a></li>
<li><a href="../files/activestorage/lib/active_storage/version_rb.html">activestorage/lib/active_storage/version.rb</a></li>
<li><a href="../files/railties/lib/rails/commands/app/update_command_rb.html">railties/lib/rails/commands/app/update_command.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
<div class="description">
<h1 id="module-ActiveStorage-label-Active+Storage">Active Storage</h1>
<p>Active Storage makes it simple to upload and reference files in cloud services like <a href="https://aws.amazon.com/s3/">Amazon S3</a>, <a href="https://cloud.google.com/storage/docs/">Google Cloud Storage</a>, or <a href="https://azure.microsoft.com/en-us/services/storage/">Microsoft Azure Storage</a>, 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.</p>
<p>Files can be uploaded from the server to the cloud or directly from the client to the cloud.</p>
<p>Image files can furthermore be transformed using on-demand variants for quality, aspect ratio, size, or any other <a href="https://github.com/minimagick/minimagick">MiniMagick</a> or <a href="https://www.rubydoc.info/gems/ruby-vips/Vips/Image">Vips</a> supported transformation.</p>
<p>You can read more about Active Storage in the <a href="https://guides.rubyonrails.org/active_storage_overview.html">Active Storage Overview</a> guide.</p>
<h2 id="module-ActiveStorage-label-Compared+to+other+storage+solutions">Compared to other storage solutions</h2>
<p>A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in <a href="https://github.com/rails/rails/blob/main/activestorage/app/models/active_storage/blob.rb">Blob</a> and <a href="https://github.com/rails/rails/blob/main/activestorage/app/models/active_storage/attachment.rb">Attachment</a> 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 <code>Attachment</code> join model, which then connects to the actual <code>Blob</code>.</p>
<p><code>Blob</code> models store attachment metadata (filename, content-type, etc.), and their identifier key in the storage service. <a href="ActiveStorage/Blob.html"><code>Blob</code></a> 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 <code>Blob</code>, 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).</p>
<h2 id="module-ActiveStorage-label-Installation">Installation</h2>
<p>Run <code>bin/rails active_storage:install</code> to copy over active_storage migrations.</p>
<p>NOTE: If the task cannot be found, verify that <code>require "active_storage/engine"</code> is present in <code>config/application.rb</code>.</p>
<h2 id="module-ActiveStorage-label-Examples">Examples</h2>
<p>One attachment:</p>
<pre><code>class User < ApplicationRecord
# Associates an attachment and a blob. When the user is destroyed they are
# purged by default (models destroyed, and resource files deleted).
has_one_attached :avatar
end
# Attach an avatar to the user.
user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpeg")
# Does the user have an avatar?
user.avatar.attached? # => true
# Synchronously destroy the avatar and actual resource files.
user.avatar.purge
# Destroy the associated models and actual resource files async, via Active Job.
user.avatar.purge_later
# Does the user have an avatar?
user.avatar.attached? # => false
# Generate a permanent URL for the blob that points to the application.
# Upon access, a redirect to the actual service endpoint is returned.
# This indirection decouples the public URL from the actual one, and
# allows for example mirroring attachments in different services for
# high-availability. The redirection has an HTTP expiration of 5 min.
url_for(user.avatar)
class AvatarsController < ApplicationController
def update
# params[:avatar] contains an ActionDispatch::Http::UploadedFile object
Current.user.avatar.attach(params.require(:avatar))
redirect_to Current.user
end
end
</code></pre>
<p>Many attachments:</p>
<pre><code>class Message < ApplicationRecord
has_many_attached :images
end
</code></pre>
<pre><code><%= form_with model: @message, local: true do |form| %>
<%= form.text_field :title, placeholder: "Title" %><br>
<%= form.textarea :content %><br><br>
<%= form.file_field :images, multiple: true %><br>
<%= form.submit %>
<% end %>
</code></pre>
<pre><code>class MessagesController < ApplicationController
def index
# Use the built-in with_attached_images scope to avoid N+1
@messages = Message.all.with_attached_images
end
def create
message = Message.create! params.expect(message: [ :title, :content, images: [] ])
redirect_to message
end
def show
@message = Message.find(params[:id])
end
end
</code></pre>
<p><a href="ActiveStorage/Variation.html"><code>Variation</code></a> of image attachment:</p>
<pre><code><%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
<%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
</code></pre>
<h2 id="module-ActiveStorage-label-File+serving+strategies"><a href="File.html"><code>File</code></a> serving strategies</h2>
<p>Active Storage supports two ways to serve files: redirecting and proxying.</p>
<h3 id="module-ActiveStorage-label-Redirecting">Redirecting</h3>
<p>Active Storage generates stable application URLs for files which, when accessed, redirect to signed, short-lived service URLs. This relieves application servers of the burden of serving file data. It is the default file serving strategy.</p>
<p>When the application is configured to proxy files by default, use the <code>rails_storage_redirect_path</code> and <code>_url</code> route helpers to redirect instead:</p>
<pre><code><%= image_tag rails_storage_redirect_path(@user.avatar) %>
</code></pre>
<h3 id="module-ActiveStorage-label-Proxying">Proxying</h3>
<p>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.</p>
<p>You can configure Active Storage to use proxying by default:</p>
<pre><code># config/initializers/active_storage.rb
Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
</code></pre>
<p>Or if you want to explicitly proxy specific attachments there are URL helpers you can use in the form of <code>rails_storage_proxy_path</code> and <code>rails_storage_proxy_url</code>.</p>
<pre><code><%= image_tag rails_storage_proxy_path(@user.avatar) %>
</code></pre>
<h2 id="module-ActiveStorage-label-Direct+uploads">Direct uploads</h2>
<p>Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.</p>
<h3 id="module-ActiveStorage-label-Direct+upload+installation">Direct upload installation</h3>
<ol><li>
<p>Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.</p>
<p>Requiring directly without bundling through the asset pipeline in the application HTML with autostart:</p>
<pre><code><%= javascript_include_tag "activestorage" %>
</code></pre>
<p>Requiring via importmap-rails without bundling through the asset pipeline in the application HTML without autostart as ESM:</p>
<pre><code># config/importmap.rb
pin "@rails/activestorage", to: "activestorage.esm.js"
</code></pre>
<pre><code><script type="module-shim">
import * as ActiveStorage from "@rails/activestorage"
ActiveStorage.start()
</script>
</code></pre>
<p>Using the asset pipeline:</p>
<pre><code>//= require activestorage
</code></pre>
<p>Using the npm package:</p>
<pre><code>import * as ActiveStorage from "@rails/activestorage"
ActiveStorage.start()
</code></pre>
</li><li>
<p>Annotate file inputs with the direct upload URL.</p>
<pre><code><%= form.file_field :attachments, multiple: true, direct_upload: true %>
</code></pre>
</li><li>
<p>That's it! Uploads begin upon form submission.</p>
</li></ol>
<h3 id="module-ActiveStorage-label-Direct+upload+JavaScript+events">Direct upload JavaScript events</h3>
<table role="table">
<thead>
<tr>
<th>Event name</th>
<th>Event target</th>
<th>Event data (‘event.detail`)</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>‘direct-uploads:start`</td>
<td>‘<form>`</td>
<td>None</td>
<td>A form containing files for direct upload fields was submitted.</td>
</tr>
<tr>
<td>‘direct-upload:initialize`</td>
<td>‘<input>`</td>
<td>‘{id, file}`</td>
<td>Dispatched for every file after form submission.</td>
</tr>
<tr>
<td>‘direct-upload:start`</td>
<td>‘<input>`</td>
<td>‘{id, file}`</td>
<td>A direct upload is starting.</td>
</tr>
<tr>
<td>‘direct-upload:before-blob-request`</td>
<td>‘<input>`</td>
<td>‘{id, file, xhr}`</td>
<td>Before making a request to your application for direct upload metadata.</td>
</tr>
<tr>
<td>‘direct-upload:before-storage-request`</td>
<td>‘<input>`</td>
<td>‘{id, file, xhr}`</td>
<td>Before making a request to store a file.</td>
</tr>
<tr>
<td>‘direct-upload:progress`</td>
<td>‘<input>`</td>
<td>‘{id, file, progress}`</td>
<td>As requests to store files progress.</td>
</tr>
<tr>
<td>‘direct-upload:error`</td>
<td>‘<input>`</td>
<td>‘{id, file, error}`</td>
<td>An error occurred. An ‘alert` will display unless this event is canceled.</td>
</tr>
<tr>
<td>‘direct-upload:end`</td>
<td>‘<input>`</td>
<td>‘{id, file}`</td>
<td>A direct upload has ended.</td>
</tr>
<tr>
<td>‘direct-uploads:end`</td>
<td>‘<form>`</td>
<td>None</td>
<td>All direct uploads have ended.</td>
</tr>
</tbody>
</table>
<h2 id="module-ActiveStorage-label-License">License</h2>
<p>Active Storage is released under the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
<h2 id="module-ActiveStorage-label-Support">Support</h2>
<p>API documentation is at:</p>
<ul><li>
<p><a href="https://api.rubyonrails.org">api.rubyonrails.org</a></p>
</li></ul>
<p>Bug reports for the Ruby on Rails project can be filed here:</p>
<ul><li>
<p><a href="https://github.com/rails/rails/issues">github.com/rails/rails/issues</a></p>
</li></ul>
<p>Feature requests should be discussed on the rails-core mailing list here:</p>
<ul><li>
<p><a href="https://discuss.rubyonrails.org/c/rubyonrails-core">discuss.rubyonrails.org/c/rubyonrails-core</a></p>
</li></ul>
</div>
<h2 id="namespace">Namespace</h2>
<h3 id="module">Module</h3>
<ul>
<li><a href="ActiveStorage/Blobs.html">ActiveStorage::Blobs</a></li>
<li><a href="ActiveStorage/DisableSession.html">ActiveStorage::DisableSession</a></li>
<li><a href="ActiveStorage/Reflection.html">ActiveStorage::Reflection</a></li>
<li><a href="ActiveStorage/Representations.html">ActiveStorage::Representations</a></li>
<li><a href="ActiveStorage/SetCurrent.html">ActiveStorage::SetCurrent</a></li>
<li><a href="ActiveStorage/Streaming.html">ActiveStorage::Streaming</a></li>
<li><a href="ActiveStorage/Transformers.html">ActiveStorage::Transformers</a></li>
<li><a href="ActiveStorage/VERSION.html">ActiveStorage::VERSION</a></li>
</ul>
<h3 id="class">Class</h3>
<ul>
<li><a href="ActiveStorage/AnalyzeJob.html">ActiveStorage::AnalyzeJob</a></li>
<li><a href="ActiveStorage/Analyzer.html">ActiveStorage::Analyzer</a></li>
<li><a href="ActiveStorage/Attached.html">ActiveStorage::Attached</a></li>
<li><a href="ActiveStorage/Attachment.html">ActiveStorage::Attachment</a></li>
<li><a href="ActiveStorage/BaseController.html">ActiveStorage::BaseController</a></li>
<li><a href="ActiveStorage/BaseJob.html">ActiveStorage::BaseJob</a></li>
<li><a href="ActiveStorage/Blob.html">ActiveStorage::Blob</a></li>
<li><a href="ActiveStorage/DirectUploadsController.html">ActiveStorage::DirectUploadsController</a></li>
<li><a href="ActiveStorage/DiskController.html">ActiveStorage::DiskController</a></li>
<li><a href="ActiveStorage/Error.html">ActiveStorage::Error</a></li>
<li><a href="ActiveStorage/FileNotFoundError.html">ActiveStorage::FileNotFoundError</a></li>
<li><a href="ActiveStorage/Filename.html">ActiveStorage::Filename</a></li>
<li><a href="ActiveStorage/FixtureSet.html">ActiveStorage::FixtureSet</a></li>
<li><a href="ActiveStorage/IntegrityError.html">ActiveStorage::IntegrityError</a></li>
<li><a href="ActiveStorage/InvariableError.html">ActiveStorage::InvariableError</a></li>
<li><a href="ActiveStorage/LogSubscriber.html">ActiveStorage::LogSubscriber</a></li>
<li><a href="ActiveStorage/MirrorJob.html">ActiveStorage::MirrorJob</a></li>
<li><a href="ActiveStorage/Preview.html">ActiveStorage::Preview</a></li>
<li><a href="ActiveStorage/PreviewError.html">ActiveStorage::PreviewError</a></li>
<li><a href="ActiveStorage/PreviewImageJob.html">ActiveStorage::PreviewImageJob</a></li>
<li><a href="ActiveStorage/Previewer.html">ActiveStorage::Previewer</a></li>
<li><a href="ActiveStorage/PurgeJob.html">ActiveStorage::PurgeJob</a></li>
<li><a href="ActiveStorage/Service.html">ActiveStorage::Service</a></li>
<li><a href="ActiveStorage/TransformJob.html">ActiveStorage::TransformJob</a></li>
<li><a href="ActiveStorage/UnpreviewableError.html">ActiveStorage::UnpreviewableError</a></li>
<li><a href="ActiveStorage/UnrepresentableError.html">ActiveStorage::UnrepresentableError</a></li>
<li><a href="ActiveStorage/Variant.html">ActiveStorage::Variant</a></li>
<li><a href="ActiveStorage/VariantRecord.html">ActiveStorage::VariantRecord</a></li>
<li><a href="ActiveStorage/VariantWithRecord.html">ActiveStorage::VariantWithRecord</a></li>
<li><a href="ActiveStorage/Variation.html">ActiveStorage::Variation</a></li>
</ul>
<h2 id="methods">Methods</h2>
<ul>
<li>
<a href="#method-c-gem_version">gem_version</a>
</li>
<li>
<a href="#method-c-version">version</a>
</li>
</ul>
<!-- Methods -->
<h2 id="class-public-methods">Class Public methods</h2>
<div class="method">
<h3 id="method-c-gem_version">
gem_version()
</h3>
<div class="description">
<p>Returns the currently loaded version of Active Storage as a <code>Gem::Version</code>.</p>
</div>
<details class="method__source">
<summary>
<span class="label">📝 Source code</span>
</summary>
<pre><code class="ruby"># File activestorage/lib/active_storage/gem_version.rb, line 5
def self.gem_version
Gem::Version.new VERSION::STRING
end</code></pre>
<a href="https://github.com/rails/rails/blob/dd8f7185faeca6ee968a6e9367f6d8601a83b8db/activestorage/lib/active_storage/gem_version.rb#L5" target="_blank" class="github_url">🔎 See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-version">
version()
</h3>
<div class="description">
<p>Returns the currently loaded version of Active Storage as a <code>Gem::Version</code>.</p>
</div>
<details class="method__source">
<summary>
<span class="label">📝 Source code</span>
</summary>
<pre><code class="ruby"># File activestorage/lib/active_storage/version.rb, line 7
def self.version
gem_version
end</code></pre>
<a href="https://github.com/rails/rails/blob/dd8f7185faeca6ee968a6e9367f6d8601a83b8db/activestorage/lib/active_storage/version.rb#L7" target="_blank" class="github_url">🔎 See on GitHub</a>
</details>
</div>
</div>
</div>
</div>