activestorage 5.2.4.4 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activestorage might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +180 -69
- data/MIT-LICENSE +1 -1
- data/README.md +43 -8
- data/app/assets/javascripts/activestorage.js +5 -2
- data/app/controllers/active_storage/base_controller.rb +13 -4
- data/app/controllers/active_storage/blobs/proxy_controller.rb +14 -0
- data/app/controllers/active_storage/{blobs_controller.rb → blobs/redirect_controller.rb} +3 -3
- data/app/controllers/active_storage/direct_uploads_controller.rb +2 -2
- data/app/controllers/active_storage/disk_controller.rb +13 -22
- data/app/controllers/active_storage/representations/proxy_controller.rb +19 -0
- data/app/controllers/active_storage/{representations_controller.rb → representations/redirect_controller.rb} +3 -3
- data/app/controllers/concerns/active_storage/file_server.rb +18 -0
- data/app/controllers/concerns/active_storage/set_blob.rb +1 -1
- data/app/controllers/concerns/active_storage/set_current.rb +15 -0
- data/app/controllers/concerns/active_storage/set_headers.rb +12 -0
- data/app/javascript/activestorage/blob_record.js +7 -2
- data/app/jobs/active_storage/analyze_job.rb +5 -0
- data/app/jobs/active_storage/base_job.rb +0 -1
- data/app/jobs/active_storage/mirror_job.rb +15 -0
- data/app/jobs/active_storage/purge_job.rb +3 -0
- data/app/models/active_storage/attachment.rb +35 -16
- data/app/models/active_storage/blob.rb +178 -68
- data/app/models/active_storage/blob/analyzable.rb +6 -2
- data/app/models/active_storage/blob/identifiable.rb +7 -6
- data/app/models/active_storage/blob/representable.rb +36 -6
- data/app/models/active_storage/filename.rb +0 -6
- data/app/models/active_storage/preview.rb +37 -12
- data/app/models/active_storage/record.rb +7 -0
- data/app/models/active_storage/variant.rb +53 -67
- data/app/models/active_storage/variant_record.rb +8 -0
- data/app/models/active_storage/variant_with_record.rb +54 -0
- data/app/models/active_storage/variation.rb +30 -34
- data/config/routes.rb +66 -15
- data/db/migrate/20170806125915_create_active_storage_tables.rb +14 -5
- data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +17 -0
- data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +11 -0
- data/lib/active_storage.rb +29 -6
- data/lib/active_storage/analyzer.rb +15 -4
- data/lib/active_storage/analyzer/image_analyzer.rb +14 -4
- data/lib/active_storage/analyzer/null_analyzer.rb +4 -0
- data/lib/active_storage/analyzer/video_analyzer.rb +17 -8
- data/lib/active_storage/attached.rb +7 -22
- data/lib/active_storage/attached/changes.rb +16 -0
- data/lib/active_storage/attached/changes/create_many.rb +47 -0
- data/lib/active_storage/attached/changes/create_one.rb +82 -0
- data/lib/active_storage/attached/changes/create_one_of_many.rb +10 -0
- data/lib/active_storage/attached/changes/delete_many.rb +27 -0
- data/lib/active_storage/attached/changes/delete_one.rb +19 -0
- data/lib/active_storage/attached/many.rb +19 -12
- data/lib/active_storage/attached/model.rb +212 -0
- data/lib/active_storage/attached/one.rb +19 -21
- data/lib/active_storage/downloader.rb +43 -0
- data/lib/active_storage/engine.rb +58 -23
- data/lib/active_storage/errors.rb +22 -3
- data/lib/active_storage/gem_version.rb +4 -4
- data/lib/active_storage/log_subscriber.rb +6 -0
- data/lib/active_storage/previewer.rb +24 -13
- data/lib/active_storage/previewer/mupdf_previewer.rb +3 -3
- data/lib/active_storage/previewer/poppler_pdf_previewer.rb +5 -5
- data/lib/active_storage/previewer/video_previewer.rb +17 -10
- data/lib/active_storage/reflection.rb +64 -0
- data/lib/active_storage/service.rb +44 -12
- data/lib/active_storage/service/azure_storage_service.rb +65 -44
- data/lib/active_storage/service/configurator.rb +6 -2
- data/lib/active_storage/service/disk_service.rb +57 -44
- data/lib/active_storage/service/gcs_service.rb +68 -64
- data/lib/active_storage/service/mirror_service.rb +31 -7
- data/lib/active_storage/service/registry.rb +32 -0
- data/lib/active_storage/service/s3_service.rb +58 -24
- data/lib/active_storage/transformers/image_processing_transformer.rb +45 -0
- data/lib/active_storage/transformers/transformer.rb +39 -0
- data/lib/tasks/activestorage.rake +7 -0
- metadata +84 -19
- data/app/models/active_storage/filename/parameters.rb +0 -36
- data/lib/active_storage/attached/macros.rb +0 -110
- data/lib/active_storage/downloading.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 124b295c01c3c6eff6f41effeacde5a082238325c9efe4830d17061ac11cb9b7
|
4
|
+
data.tar.gz: 8135dbbb73ca1899c0c1a9c8a94f8454ba22a41cc056d70061152ed2b08b382c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49766c17d18452f00567a08aaf3eaee82e1dfd0f30f80d58612dd831a1829ef907af85662eda9feb05917588d2f4dcde7527e77a8d1c71037367a49a218d4a16
|
7
|
+
data.tar.gz: 455808755addc5e43524a7bc9d7469c9b04a292e56098a40569342190e6cc74c183046238d743ccc21b67d7d1a6c5d287e4fb551e5e91a2e81955ff3702a6dc9
|
data/CHANGELOG.md
CHANGED
@@ -1,137 +1,248 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Fix S3 multipart uploads when threshold is larger than file.
|
4
4
|
|
5
|
+
*Matt Muller*
|
5
6
|
|
6
|
-
## Rails 5.2.4.3 (May 18, 2020) ##
|
7
7
|
|
8
|
-
|
8
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
9
9
|
|
10
|
+
* Change default queue name of the analysis (`:active_storage_analysis`) and
|
11
|
+
purge (`:active_storage_purge`) jobs to be the job adapter's default (`:default`).
|
10
12
|
|
11
|
-
|
13
|
+
*Rafael Mendonça França*
|
12
14
|
|
13
|
-
*
|
15
|
+
* Implement `strict_loading` on ActiveStorage associations.
|
14
16
|
|
17
|
+
*David Angulo*
|
15
18
|
|
16
|
-
|
19
|
+
* Remove deprecated support to pass `:combine_options` operations to `ActiveStorage::Transformers::ImageProcessing`.
|
17
20
|
|
18
|
-
*
|
21
|
+
*Rafael Mendonça França*
|
19
22
|
|
23
|
+
* Remove deprecated `ActiveStorage::Transformers::MiniMagickTransformer`.
|
20
24
|
|
21
|
-
|
25
|
+
*Rafael Mendonça França*
|
22
26
|
|
23
|
-
*
|
27
|
+
* Remove deprecated `config.active_storage.queue`.
|
24
28
|
|
29
|
+
*Rafael Mendonça França*
|
25
30
|
|
26
|
-
|
31
|
+
* Remove deprecated `ActiveStorage::Downloading`.
|
27
32
|
|
28
|
-
*
|
33
|
+
*Rafael Mendonça França*
|
29
34
|
|
35
|
+
* Add per-environment configuration support
|
30
36
|
|
31
|
-
|
37
|
+
*Pietro Moro*
|
32
38
|
|
33
|
-
*
|
39
|
+
* The Poppler PDF previewer renders a preview image using the original
|
40
|
+
document's crop box rather than its media box, hiding print margins. This
|
41
|
+
matches the behavior of the MuPDF previewer.
|
34
42
|
|
35
|
-
*
|
43
|
+
*Vincent Robert*
|
36
44
|
|
37
|
-
*
|
45
|
+
* Touch parent model when an attachment is purged.
|
38
46
|
|
39
|
-
*
|
47
|
+
*Víctor Pérez Rodríguez*
|
40
48
|
|
41
|
-
*
|
49
|
+
* Files can now be served by proxying them from the underlying storage service
|
50
|
+
instead of redirecting to a signed service URL. Use the
|
51
|
+
`rails_storage_proxy_path` and `_url` helpers to proxy an attached file:
|
42
52
|
|
43
|
-
|
53
|
+
```erb
|
54
|
+
<%= image_tag rails_storage_proxy_path(@user.avatar) %>
|
55
|
+
```
|
44
56
|
|
45
|
-
|
57
|
+
To proxy by default, set `config.active_storage.resolve_model_to_route`:
|
46
58
|
|
47
|
-
|
59
|
+
```ruby
|
60
|
+
# Proxy attached files instead.
|
61
|
+
config.active_storage.resolve_model_to_route = :rails_storage_proxy
|
62
|
+
```
|
48
63
|
|
49
|
-
|
64
|
+
```erb
|
65
|
+
<%= image_tag @user.avatar %>
|
66
|
+
```
|
50
67
|
|
51
|
-
|
68
|
+
To redirect to a signed service URL when the default file serving strategy
|
69
|
+
is set to proxying, use the `rails_storage_redirect_path` and `_url` helpers:
|
70
|
+
|
71
|
+
```erb
|
72
|
+
<%= image_tag rails_storage_redirect_path(@user.avatar) %>
|
73
|
+
```
|
74
|
+
|
75
|
+
*Jonathan Fleckenstein*
|
76
|
+
|
77
|
+
* Add `config.active_storage.web_image_content_types` to allow applications
|
78
|
+
to add content types (like `image/webp`) in which variants can be processed,
|
79
|
+
instead of letting those images be converted to the fallback PNG format.
|
80
|
+
|
81
|
+
*Jeroen van Haperen*
|
82
|
+
|
83
|
+
* Add support for creating variants of `WebP` images out of the box.
|
84
|
+
|
85
|
+
*Dino Maric*
|
52
86
|
|
87
|
+
* Only enqueue analysis jobs for blobs with non-null analyzer classes.
|
53
88
|
|
54
|
-
|
89
|
+
*Gannon McGibbon*
|
55
90
|
|
56
|
-
*
|
91
|
+
* Previews are created on the same service as the original blob.
|
57
92
|
|
58
|
-
|
93
|
+
*Peter Zhu*
|
59
94
|
|
60
|
-
|
95
|
+
* Remove unused `disposition` and `content_type` query parameters for `DiskService`.
|
61
96
|
|
97
|
+
*Peter Zhu*
|
62
98
|
|
63
|
-
|
99
|
+
* Use `DiskController` for both public and private files.
|
64
100
|
|
65
|
-
|
101
|
+
`DiskController` is able to handle multiple services by adding a
|
102
|
+
`service_name` field in the generated URL in `DiskService`.
|
103
|
+
|
104
|
+
*Peter Zhu*
|
105
|
+
|
106
|
+
* Variants are tracked in the database to avoid existence checks in the storage service.
|
66
107
|
|
67
108
|
*George Claghorn*
|
68
109
|
|
69
|
-
*
|
110
|
+
* Deprecate `service_url` methods in favour of `url`.
|
111
|
+
|
112
|
+
Deprecate `Variant#service_url` and `Preview#service_url` to instead use
|
113
|
+
`#url` method to be consistent with `Blob`.
|
114
|
+
|
115
|
+
*Peter Zhu*
|
70
116
|
|
71
|
-
|
117
|
+
* Permanent URLs for public storage blobs.
|
72
118
|
|
119
|
+
Services can be configured in `config/storage.yml` with a new key
|
120
|
+
`public: true | false` to indicate whether a service holds public
|
121
|
+
blobs or private blobs. Public services will always return a permanent URL.
|
73
122
|
|
74
|
-
|
123
|
+
Deprecates `Blob#service_url` in favor of `Blob#url`.
|
75
124
|
|
76
|
-
*
|
77
|
-
explicit AWS key pair and/or region is not provided in `storage.yml`,
|
78
|
-
attempt to use environment variables, shared credentials, or IAM
|
79
|
-
(instance or task) role credentials. Order of precedence is determined
|
80
|
-
by the [AWS SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
|
125
|
+
*Peter Zhu*
|
81
126
|
|
82
|
-
|
127
|
+
* Make services aware of configuration names.
|
83
128
|
|
84
|
-
*
|
129
|
+
*Gannon McGibbon*
|
85
130
|
|
86
|
-
|
87
|
-
that is ambiguous in meaning. It needs to be set to the primary blob
|
88
|
-
storage endpoint but that can be determined from the blobs client anyway.
|
131
|
+
* The `Content-Type` header is set on image variants when they're uploaded to third-party storage services.
|
89
132
|
|
90
|
-
|
91
|
-
now get the endpoint from the blobs client instead.
|
133
|
+
*Kyle Ribordy*
|
92
134
|
|
93
|
-
|
135
|
+
* Allow storage services to be configured per attachment.
|
94
136
|
|
95
|
-
|
137
|
+
```ruby
|
138
|
+
class User < ActiveRecord::Base
|
139
|
+
has_one_attached :avatar, service: :s3
|
140
|
+
end
|
96
141
|
|
97
|
-
|
142
|
+
class Gallery < ActiveRecord::Base
|
143
|
+
has_many_attached :photos, service: :s3
|
144
|
+
end
|
145
|
+
```
|
98
146
|
|
99
|
-
|
147
|
+
*Dmitry Tsepelev*
|
148
|
+
|
149
|
+
* You can optionally provide a custom blob key when attaching a new file:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
user.avatar.attach key: "avatars/#{user.id}.jpg",
|
153
|
+
io: io, content_type: "image/jpeg", filename: "avatar.jpg"
|
154
|
+
```
|
155
|
+
|
156
|
+
Active Storage will store the blob's data on the configured service at the provided key.
|
100
157
|
|
101
158
|
*George Claghorn*
|
102
159
|
|
103
|
-
*
|
160
|
+
* Replace `Blob.create_after_upload!` with `Blob.create_and_upload!` and deprecate the former.
|
161
|
+
|
162
|
+
`create_after_upload!` has been removed since it could lead to data
|
163
|
+
corruption by uploading to a key on the storage service which happened to
|
164
|
+
be already taken. Creating the record would then correctly raise a
|
165
|
+
database uniqueness exception but the stored object would already have
|
166
|
+
overwritten another. `create_and_upload!` swaps the order of operations
|
167
|
+
so that the key gets reserved up-front or the uniqueness error gets raised,
|
168
|
+
before the upload to a key takes place.
|
104
169
|
|
105
|
-
|
106
|
-
rather than the compiled code, which can produce smaller javascript bundles.
|
170
|
+
*Julik Tarkhanov*
|
107
171
|
|
108
|
-
|
172
|
+
* Set content disposition in direct upload using `filename` and `disposition` parameters to `ActiveStorage::Service#headers_for_direct_upload`.
|
109
173
|
|
110
|
-
*
|
111
|
-
with rectangular samples in `ActiveStorage::Analyzer::VideoAnalyzer`.
|
174
|
+
*Peter Zhu*
|
112
175
|
|
113
|
-
|
114
|
-
|
115
|
-
|
176
|
+
* Allow record to be optionally passed to blob finders to make sharding
|
177
|
+
easier.
|
178
|
+
|
179
|
+
*Gannon McGibbon*
|
180
|
+
|
181
|
+
* Switch from `azure-storage` gem to `azure-storage-blob` gem for Azure service.
|
182
|
+
|
183
|
+
*Peter Zhu*
|
184
|
+
|
185
|
+
* Add `config.active_storage.draw_routes` to disable Active Storage routes.
|
186
|
+
|
187
|
+
*Gannon McGibbon*
|
188
|
+
|
189
|
+
* Image analysis is skipped if ImageMagick returns an error.
|
190
|
+
|
191
|
+
`ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a
|
192
|
+
`MiniMagick::Error`, which caused persistent `ActiveStorage::AnalyzeJob`
|
193
|
+
failures. It now logs the error and returns `{}`, resulting in no metadata
|
194
|
+
being added to the offending image blob.
|
116
195
|
|
117
196
|
*George Claghorn*
|
118
197
|
|
119
|
-
*
|
120
|
-
|
198
|
+
* Method calls on singular attachments return `nil` when no file is attached.
|
199
|
+
|
200
|
+
Previously, assuming the following User model, `user.avatar.filename` would
|
201
|
+
raise a `Module::DelegationError` if no avatar was attached:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
class User < ApplicationRecord
|
205
|
+
has_one_attached :avatar
|
206
|
+
end
|
207
|
+
```
|
121
208
|
|
122
|
-
|
209
|
+
They now return `nil`.
|
123
210
|
|
124
|
-
*
|
125
|
-
This mitigates possible security issues such as XSS or phishing when
|
126
|
-
serving them inline. A list of such content types is included by default,
|
127
|
-
and can be configured via `content_types_to_serve_as_binary`.
|
211
|
+
*Matthew Tanous*
|
128
212
|
|
129
|
-
|
213
|
+
* The mirror service supports direct uploads.
|
130
214
|
|
131
|
-
|
215
|
+
New files are directly uploaded to the primary service. When a
|
216
|
+
directly-uploaded file is attached to a record, a background job is enqueued
|
217
|
+
to copy it to each secondary service.
|
132
218
|
|
133
|
-
|
219
|
+
Configure the queue used to process mirroring jobs by setting
|
220
|
+
`config.active_storage.queues.mirror`. The default is `:active_storage_mirror`.
|
221
|
+
|
222
|
+
*George Claghorn*
|
223
|
+
|
224
|
+
* The S3 service now permits uploading files larger than 5 gigabytes.
|
225
|
+
|
226
|
+
When uploading a file greater than 100 megabytes in size, the service
|
227
|
+
transparently switches to [multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html)
|
228
|
+
using a part size computed from the file's total size and S3's part count limit.
|
229
|
+
|
230
|
+
No application changes are necessary to take advantage of this feature. You
|
231
|
+
can customize the default 100 MB multipart upload threshold in your S3
|
232
|
+
service's configuration:
|
233
|
+
|
234
|
+
```yaml
|
235
|
+
production:
|
236
|
+
service: s3
|
237
|
+
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
238
|
+
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
239
|
+
region: us-east-1
|
240
|
+
bucket: my-bucket
|
241
|
+
upload:
|
242
|
+
multipart_threshold: <%= 250.megabytes %>
|
243
|
+
```
|
244
|
+
|
245
|
+
*George Claghorn*
|
134
246
|
|
135
|
-
* Added to Rails.
|
136
247
|
|
137
|
-
|
248
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activestorage/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -4,17 +4,21 @@ Active Storage makes it simple to upload and reference files in cloud services l
|
|
4
4
|
|
5
5
|
Files can be uploaded from the server to the cloud or directly from the client to the cloud.
|
6
6
|
|
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) supported transformation.
|
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
|
+
|
9
|
+
You can read more about Active Storage in the [Active Storage Overview](https://edgeguides.rubyonrails.org/active_storage_overview.html) guide.
|
8
10
|
|
9
11
|
## Compared to other storage solutions
|
10
12
|
|
11
|
-
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/
|
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/master/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/master/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`.
|
12
14
|
|
13
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).
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
17
|
-
Run `rails active_storage:install` to copy over active_storage migrations.
|
19
|
+
Run `bin/rails active_storage:install` to copy over active_storage migrations.
|
20
|
+
|
21
|
+
NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.
|
18
22
|
|
19
23
|
## Examples
|
20
24
|
|
@@ -51,7 +55,7 @@ url_for(user.avatar)
|
|
51
55
|
|
52
56
|
class AvatarsController < ApplicationController
|
53
57
|
def update
|
54
|
-
# params[:avatar] contains
|
58
|
+
# params[:avatar] contains an ActionDispatch::Http::UploadedFile object
|
55
59
|
Current.user.avatar.attach(params.require(:avatar))
|
56
60
|
redirect_to Current.user
|
57
61
|
end
|
@@ -99,7 +103,38 @@ Variation of image attachment:
|
|
99
103
|
|
100
104
|
```erb
|
101
105
|
<%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
|
102
|
-
<%= image_tag user.avatar.variant(
|
106
|
+
<%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
|
107
|
+
```
|
108
|
+
|
109
|
+
## File serving strategies
|
110
|
+
|
111
|
+
Active Storage supports two ways to serve files: redirecting and proxying.
|
112
|
+
|
113
|
+
### Redirecting
|
114
|
+
|
115
|
+
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.
|
116
|
+
|
117
|
+
When the application is configured to proxy files by default, use the `rails_storage_redirect_path` and `_url` route helpers to redirect instead:
|
118
|
+
|
119
|
+
```erb
|
120
|
+
<%= image_tag rails_storage_redirect_path(@user.avatar) %>
|
121
|
+
```
|
122
|
+
|
123
|
+
### Proxying
|
124
|
+
|
125
|
+
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
|
+
|
127
|
+
Explicitly proxy attachments using the `rails_storage_proxy_path` and `_url` route helpers:
|
128
|
+
|
129
|
+
```erb
|
130
|
+
<%= image_tag rails_storage_proxy_path(@user.avatar) %>
|
131
|
+
```
|
132
|
+
|
133
|
+
Or configure Active Storage to use proxying by default:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
# config/initializers/active_storage.rb
|
137
|
+
Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
|
103
138
|
```
|
104
139
|
|
105
140
|
## Direct uploads
|
@@ -116,7 +151,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
|
|
116
151
|
```
|
117
152
|
Using the npm package:
|
118
153
|
```js
|
119
|
-
import * as ActiveStorage from "activestorage"
|
154
|
+
import * as ActiveStorage from "@rails/activestorage"
|
120
155
|
ActiveStorage.start()
|
121
156
|
```
|
122
157
|
2. Annotate file inputs with the direct upload URL.
|
@@ -148,7 +183,7 @@ Active Storage is released under the [MIT License](https://opensource.org/licens
|
|
148
183
|
|
149
184
|
API documentation is at:
|
150
185
|
|
151
|
-
*
|
186
|
+
* https://api.rubyonrails.org
|
152
187
|
|
153
188
|
Bug reports for the Ruby on Rails project can be filed here:
|
154
189
|
|
@@ -156,4 +191,4 @@ Bug reports for the Ruby on Rails project can be filed here:
|
|
156
191
|
|
157
192
|
Feature requests should be discussed on the rails-core mailing list here:
|
158
193
|
|
159
|
-
* https://
|
194
|
+
* https://discuss.rubyonrails.org/c/rubyonrails-core
|
@@ -550,7 +550,7 @@
|
|
550
550
|
this.file = file;
|
551
551
|
this.attributes = {
|
552
552
|
filename: file.name,
|
553
|
-
content_type: file.type,
|
553
|
+
content_type: file.type || "application/octet-stream",
|
554
554
|
byte_size: file.size,
|
555
555
|
checksum: checksum
|
556
556
|
};
|
@@ -560,7 +560,10 @@
|
|
560
560
|
this.xhr.setRequestHeader("Content-Type", "application/json");
|
561
561
|
this.xhr.setRequestHeader("Accept", "application/json");
|
562
562
|
this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
563
|
-
|
563
|
+
var csrfToken = getMetaValue("csrf-token");
|
564
|
+
if (csrfToken != undefined) {
|
565
|
+
this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
566
|
+
}
|
564
567
|
this.xhr.addEventListener("load", function(event) {
|
565
568
|
return _this.requestDidLoad(event);
|
566
569
|
});
|