activestorage 5.2.2.1 → 6.0.2

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.

Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -58
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +9 -6
  5. data/app/assets/javascripts/activestorage.js +4 -1
  6. data/app/controllers/active_storage/base_controller.rb +3 -5
  7. data/app/controllers/active_storage/blobs_controller.rb +1 -1
  8. data/app/controllers/active_storage/disk_controller.rb +5 -2
  9. data/app/controllers/active_storage/representations_controller.rb +1 -1
  10. data/app/controllers/concerns/active_storage/set_current.rb +15 -0
  11. data/app/javascript/activestorage/blob_record.js +6 -1
  12. data/app/jobs/active_storage/analyze_job.rb +5 -0
  13. data/app/jobs/active_storage/base_job.rb +0 -1
  14. data/app/jobs/active_storage/purge_job.rb +3 -0
  15. data/app/models/active_storage/attachment.rb +20 -9
  16. data/app/models/active_storage/blob.rb +89 -34
  17. data/app/models/active_storage/blob/representable.rb +5 -5
  18. data/app/models/active_storage/filename.rb +0 -6
  19. data/app/models/active_storage/preview.rb +3 -3
  20. data/app/models/active_storage/variant.rb +51 -52
  21. data/app/models/active_storage/variation.rb +24 -33
  22. data/config/routes.rb +13 -12
  23. data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +9 -0
  24. data/lib/active_storage.rb +26 -6
  25. data/lib/active_storage/analyzer.rb +9 -4
  26. data/lib/active_storage/analyzer/image_analyzer.rb +11 -4
  27. data/lib/active_storage/analyzer/video_analyzer.rb +3 -5
  28. data/lib/active_storage/attached.rb +7 -22
  29. data/lib/active_storage/attached/changes.rb +16 -0
  30. data/lib/active_storage/attached/changes/create_many.rb +46 -0
  31. data/lib/active_storage/attached/changes/create_one.rb +69 -0
  32. data/lib/active_storage/attached/changes/create_one_of_many.rb +10 -0
  33. data/lib/active_storage/attached/changes/delete_many.rb +27 -0
  34. data/lib/active_storage/attached/changes/delete_one.rb +19 -0
  35. data/lib/active_storage/attached/many.rb +16 -10
  36. data/lib/active_storage/attached/model.rb +147 -0
  37. data/lib/active_storage/attached/one.rb +16 -19
  38. data/lib/active_storage/downloader.rb +43 -0
  39. data/lib/active_storage/downloading.rb +8 -0
  40. data/lib/active_storage/engine.rb +43 -6
  41. data/lib/active_storage/errors.rb +22 -3
  42. data/lib/active_storage/gem_version.rb +3 -3
  43. data/lib/active_storage/previewer.rb +21 -11
  44. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +2 -2
  45. data/lib/active_storage/previewer/video_previewer.rb +2 -3
  46. data/lib/active_storage/reflection.rb +64 -0
  47. data/lib/active_storage/service.rb +9 -6
  48. data/lib/active_storage/service/azure_storage_service.rb +30 -14
  49. data/lib/active_storage/service/configurator.rb +3 -1
  50. data/lib/active_storage/service/disk_service.rb +24 -12
  51. data/lib/active_storage/service/gcs_service.rb +49 -47
  52. data/lib/active_storage/service/mirror_service.rb +1 -1
  53. data/lib/active_storage/service/s3_service.rb +10 -6
  54. data/lib/active_storage/transformers/image_processing_transformer.rb +39 -0
  55. data/lib/active_storage/transformers/mini_magick_transformer.rb +38 -0
  56. data/lib/active_storage/transformers/transformer.rb +42 -0
  57. data/lib/tasks/activestorage.rake +7 -0
  58. metadata +42 -13
  59. data/app/models/active_storage/filename/parameters.rb +0 -36
  60. data/lib/active_storage/attached/macros.rb +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0d20f7134564917b1c096461f7e26b425ae8e00309acfaa3f9d735f4ec09d81
4
- data.tar.gz: 6e84f459bb3dfcd0bcfb26c3eeddb0fd8dff5ff3ed9be89aaa91df5357e51fff
3
+ metadata.gz: 9f2b9362dae6e300c461389e6cae8d1b8b9899e8f672e94c6ca01f34dd92b294
4
+ data.tar.gz: f6a095b91aec69b8413a84defa928275afb593bcfc2aa5671265146bcdb9add3
5
5
  SHA512:
6
- metadata.gz: b259624820a5e8fe4ab38db0ed82f4d90808fb62b6fa82821c0e3dbca9b0163f390d9827c77aad70d449523c2e530d9294bfce4c41ba490ea0c1c1b20c451908
7
- data.tar.gz: e35056365e06a75f1f5c36e3bc9ca3c0b630eb0026eab831a41a390e9ffb40642cb62cc8f2de478d2021d637934d13c01eb1462114ee96893cb4476543806dc6
6
+ metadata.gz: 8919cb495d0d704490a3284ef8e2fc8368171a51390aacb02ca762dd213fc79fe11a765a0f6026e111551b99bd32e1dd43e8c06fe2eac401aa36b231bf364f73
7
+ data.tar.gz: 58a1a071dbd6749ef172ed8b29258c74e928a57071555013a27da08fffe93aed043c44a454643a72825e4392e4a7a9d8349a5e47f45cbb4a9ac189c97761c37f
@@ -1,112 +1,216 @@
1
- ## Rails 5.2.2.1 (March 11, 2019) ##
1
+ ## Rails 6.0.2 (December 13, 2019) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 5.2.2 (December 04, 2018) ##
6
+ ## Rails 6.0.1 (November 5, 2019) ##
7
7
 
8
- * Support multiple submit buttons in Active Storage forms.
8
+ * `ActiveStorage::AnalyzeJob`s are discarded on `ActiveRecord::RecordNotFound` errors.
9
9
 
10
- *Chrıs Seelus*
10
+ *George Claghorn*
11
11
 
12
- * Fix `ArgumentError` when uploading to amazon s3
12
+ * Blobs are recorded in the database before being uploaded to the service.
13
+ This fixes that generated blob keys could silently collide, leading to
14
+ data loss.
13
15
 
14
- *Hiroki Sanpei*
16
+ *Julik Tarkhanov*
15
17
 
16
- * Add a foreign-key constraint to the `active_storage_attachments` table for blobs.
17
18
 
18
- *George Claghorn*
19
+ ## Rails 6.0.0 (August 16, 2019) ##
19
20
 
20
- * Discard `ActiveStorage::PurgeJobs` for missing blobs.
21
+ * No changes.
21
22
 
22
- *George Claghorn*
23
23
 
24
- * Fix uploading Tempfiles to Azure Storage.
24
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
25
25
 
26
- *George Claghorn*
26
+ * No changes.
27
27
 
28
28
 
29
- ## Rails 5.2.1.1 (November 27, 2018) ##
29
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
30
30
 
31
- * Prevent content type and disposition bypass in storage service URLs.
31
+ * Don't raise when analyzing an image whose type is unsupported by ImageMagick.
32
32
 
33
- Fix CVE-2018-16477.
33
+ Fixes #36065.
34
34
 
35
- *Rosa Gutierrez*
35
+ *Guilherme Mansur*
36
36
 
37
+ * Permit generating variants of BMP images.
37
38
 
38
- ## Rails 5.2.1 (August 07, 2018) ##
39
+ *Younes Serraj*
39
40
 
40
- * Fix direct upload with zero-byte files.
41
41
 
42
- *George Claghorn*
42
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
43
+
44
+ * No changes.
45
+
43
46
 
44
- * Exclude JSON root from `active_storage/direct_uploads#create` response.
47
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
48
+
49
+ * No changes.
50
+
51
+
52
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
53
+
54
+ * [Rename npm package](https://github.com/rails/rails/pull/34905) from
55
+ [`activestorage`](https://www.npmjs.com/package/activestorage) to
56
+ [`@rails/activestorage`](https://www.npmjs.com/package/@rails/activestorage).
45
57
 
46
58
  *Javan Makhmali*
47
59
 
60
+ * Replace `config.active_storage.queue` with two options that indicate which
61
+ queues analysis and purge jobs should use, respectively:
62
+
63
+ * `config.active_storage.queues.analysis`
64
+ * `config.active_storage.queues.purge`
65
+
66
+ `config.active_storage.queue` is preferred over the new options when it's
67
+ set, but it is deprecated and will be removed in Rails 6.1.
68
+
69
+ *George Claghorn*
70
+
71
+ * Permit generating variants of TIFF images.
72
+
73
+ *Luciano Sousa*
74
+
75
+ * Use base36 (all lowercase) for all new Blob keys to prevent
76
+ collisions and undefined behavior with case-insensitive filesystems and
77
+ database indices.
48
78
 
49
- ## Rails 5.2.0 (April 09, 2018) ##
79
+ *Julik Tarkhanov*
50
80
 
51
- * Allow full use of the AWS S3 SDK options for authentication. If an
52
- explicit AWS key pair and/or region is not provided in `storage.yml`,
53
- attempt to use environment variables, shared credentials, or IAM
54
- (instance or task) role credentials. Order of precedence is determined
55
- by the [AWS SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
81
+ * It doesn’t include an `X-CSRF-Token` header if a meta tag is not found on
82
+ the page. It previously included one with a value of `undefined`.
56
83
 
57
- *Brian Knight*
84
+ *Cameron Bothner*
58
85
 
59
- * Remove path config option from Azure service.
86
+ * Fix `ArgumentError` when uploading to amazon s3
87
+
88
+ *Hiroki Sanpei*
89
+
90
+ * Add progressive JPG to default list of variable content types
91
+
92
+ *Maurice Kühlborn*
93
+
94
+ * Add `ActiveStorage.routes_prefix` for configuring generated routes.
95
+
96
+ *Chris Bisnett*
97
+
98
+ * `ActiveStorage::Service::AzureStorageService` only handles specifically
99
+ relevant types of `Azure::Core::Http::HTTPError`. It previously obscured
100
+ other types of `HTTPError`, which is the azure-storage gem’s catch-all
101
+ exception class.
102
+
103
+ *Cameron Bothner*
104
+
105
+ * `ActiveStorage::DiskController#show` generates a 404 Not Found response when
106
+ the requested file is missing from the disk service. It previously raised
107
+ `Errno::ENOENT`.
108
+
109
+ *Cameron Bothner*
110
+
111
+ * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
112
+ `ActiveStorage::FileNotFoundError` when the corresponding file is missing
113
+ from the storage service. Services translate service-specific missing object
114
+ exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and
115
+ `Errno::ENOENT` for the disk service) into
116
+ `ActiveStorage::FileNotFoundError`.
60
117
 
61
- The Active Storage service for Azure Storage has an option called `path`
62
- that is ambiguous in meaning. It needs to be set to the primary blob
63
- storage endpoint but that can be determined from the blobs client anyway.
118
+ *Cameron Bothner*
64
119
 
65
- To simplify the configuration, we've removed the `path` option and
66
- now get the endpoint from the blobs client instead.
120
+ * Added the `ActiveStorage::SetCurrent` concern for custom Active Storage
121
+ controllers that can't inherit from `ActiveStorage::BaseController`.
67
122
 
68
- Closes #32225.
123
+ *George Claghorn*
124
+
125
+ * Active Storage error classes like `ActiveStorage::IntegrityError` and
126
+ `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
127
+ instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
128
+ handle all Active Storage errors.
129
+
130
+ *Andrei Makarov*, *George Claghorn*
69
131
 
70
- *Andrew White*
132
+ * Uploaded files assigned to a record are persisted to storage when the record
133
+ is saved instead of immediately.
71
134
 
72
- * Generate root-relative paths in disk service URL methods.
135
+ In Rails 5.2, the following causes an uploaded file in `params[:avatar]` to
136
+ be stored:
73
137
 
74
- Obviate the disk service's `:host` configuration option.
138
+ ```ruby
139
+ @user.avatar = params[:avatar]
140
+ ```
141
+
142
+ In Rails 6, the uploaded file is stored when `@user` is successfully saved.
75
143
 
76
144
  *George Claghorn*
77
145
 
78
- * Add source code to published npm package.
146
+ * Add the ability to reflect on defined attachments using the existing
147
+ ActiveRecord reflection mechanism.
148
+
149
+ *Kevin Deisz*
150
+
151
+ * Variant arguments of `false` or `nil` will no longer be passed to the
152
+ processor. For example, the following will not have the monochrome
153
+ variation applied:
154
+
155
+ ```ruby
156
+ avatar.variant(monochrome: false)
157
+ ```
158
+
159
+ *Jacob Smith*
160
+
161
+ * Generated attachment getter and setter methods are created
162
+ within the model's `GeneratedAssociationMethods` module to
163
+ allow overriding and composition using `super`.
164
+
165
+ *Josh Susser*, *Jamon Douglas*
166
+
167
+ * Add `ActiveStorage::Blob#open`, which downloads a blob to a tempfile on disk
168
+ and yields the tempfile. Deprecate `ActiveStorage::Downloading`.
169
+
170
+ *David Robertson*, *George Claghorn*
79
171
 
80
- This allows activestorage users to depend on the javascript source code
81
- rather than the compiled code, which can produce smaller javascript bundles.
172
+ * Pass in `identify: false` as an argument when providing a `content_type` for
173
+ `ActiveStorage::Attached::{One,Many}#attach` to bypass automatic content
174
+ type inference. For example:
82
175
 
83
- *Richard Macklin*
176
+ ```ruby
177
+ @message.image.attach(
178
+ io: File.open('/path/to/file'),
179
+ filename: 'file.pdf',
180
+ content_type: 'application/pdf',
181
+ identify: false
182
+ )
183
+ ```
84
184
 
85
- * Preserve display aspect ratio when extracting width and height from videos
86
- with rectangular samples in `ActiveStorage::Analyzer::VideoAnalyzer`.
185
+ *Ryan Davidson*
87
186
 
88
- When a video contains a display aspect ratio, emit it in metadata as
89
- `:display_aspect_ratio` rather than the ambiguous `:aspect_ratio`. Compute
90
- its height by scaling its encoded frame width according to the DAR.
187
+ * The Google Cloud Storage service properly supports streaming downloads.
188
+ It now requires version 1.11 or newer of the google-cloud-storage gem.
91
189
 
92
190
  *George Claghorn*
93
191
 
94
- * Use `after_destroy_commit` instead of `before_destroy` for purging
95
- attachments when a record is destroyed.
192
+ * Use the [ImageProcessing](https://github.com/janko-m/image_processing) gem
193
+ for Active Storage variants, and deprecate the MiniMagick backend.
96
194
 
97
- *Hiroki Zenigami*
195
+ This means that variants are now automatically oriented if the original
196
+ image was rotated. Also, in addition to the existing ImageMagick
197
+ operations, variants can now use `:resize_to_fit`, `:resize_to_fill`, and
198
+ other ImageProcessing macros. These are now recommended over raw `:resize`,
199
+ as they also sharpen the thumbnail after resizing.
98
200
 
99
- * Force `:attachment` disposition for specific, configurable content types.
100
- This mitigates possible security issues such as XSS or phishing when
101
- serving them inline. A list of such content types is included by default,
102
- and can be configured via `content_types_to_serve_as_binary`.
201
+ The ImageProcessing gem also comes with a backend implemented on
202
+ [libvips](http://jcupitt.github.io/libvips/), an alternative to
203
+ ImageMagick which has significantly better performance than
204
+ ImageMagick in most cases, both in terms of speed and memory usage. In
205
+ Active Storage it's now possible to switch to the libvips backend by
206
+ changing `Rails.application.config.active_storage.variant_processor` to
207
+ `:vips`.
103
208
 
104
- *Rosa Gutierrez*
209
+ *Janko Marohnić*
105
210
 
106
- * Fix the gem adding the migrations files to the package.
211
+ * Rails 6 requires Ruby 2.5.0 or newer.
107
212
 
108
- *Yuji Yaginuma*
213
+ *Jeremy Daer*, *Kasper Timm Hansen*
109
214
 
110
- * Added to Rails.
111
215
 
112
- *DHH*
216
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2018 David Heinemeier Hansson, Basecamp
1
+ Copyright (c) 2017-2019 David Heinemeier Hansson, Basecamp
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,11 +4,13 @@ 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/5-2-stable/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/5-2-stable/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/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
 
@@ -16,6 +18,8 @@ A key difference to how Active Storage works compared to other attachment soluti
16
18
 
17
19
  Run `rails active_storage:install` to copy over active_storage migrations.
18
20
 
21
+ NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.
22
+
19
23
  ## Examples
20
24
 
21
25
  One attachment:
@@ -99,7 +103,7 @@ 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(resize: "100x100") %>
106
+ <%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
103
107
  ```
104
108
 
105
109
  ## Direct uploads
@@ -116,8 +120,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
116
120
  ```
117
121
  Using the npm package:
118
122
  ```js
119
- import * as ActiveStorage from "activestorage"
120
- ActiveStorage.start()
123
+ require("@rails/activestorage").start()
121
124
  ```
122
125
  2. Annotate file inputs with the direct upload URL.
123
126
 
@@ -148,7 +151,7 @@ Active Storage is released under the [MIT License](https://opensource.org/licens
148
151
 
149
152
  API documentation is at:
150
153
 
151
- * http://api.rubyonrails.org
154
+ * https://api.rubyonrails.org
152
155
 
153
156
  Bug reports for the Ruby on Rails project can be filed here:
154
157
 
@@ -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
- this.xhr.setRequestHeader("X-CSRF-Token", getMetaValue("csrf-token"));
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
  });
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The base controller for all ActiveStorage controllers.
3
+ # The base class for all Active Storage controllers.
4
4
  class ActiveStorage::BaseController < ActionController::Base
5
- protect_from_forgery with: :exception
5
+ include ActiveStorage::SetCurrent
6
6
 
7
- before_action do
8
- ActiveStorage::Current.host = request.base_url
9
- end
7
+ protect_from_forgery with: :exception
10
8
  end
@@ -8,7 +8,7 @@ class ActiveStorage::BlobsController < ActiveStorage::BaseController
8
8
  include ActiveStorage::SetBlob
9
9
 
10
10
  def show
11
- expires_in ActiveStorage::Blob.service.url_expires_in
11
+ expires_in ActiveStorage.service_urls_expire_in
12
12
  redirect_to @blob.service_url(disposition: params[:disposition])
13
13
  end
14
14
  end
@@ -3,7 +3,7 @@
3
3
  # Serves files stored with the disk service in the same way that the cloud services do.
4
4
  # This means using expiring, signed URLs that are meant for immediate access, not permanent linking.
5
5
  # Always go through the BlobsController, or your own authenticated controller, rather than directly
6
- # to the service url.
6
+ # to the service URL.
7
7
  class ActiveStorage::DiskController < ActiveStorage::BaseController
8
8
  skip_forgery_protection
9
9
 
@@ -13,16 +13,19 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
13
13
  else
14
14
  head :not_found
15
15
  end
16
+ rescue Errno::ENOENT
17
+ head :not_found
16
18
  end
17
19
 
18
20
  def update
19
21
  if token = decode_verified_token
20
22
  if acceptable_content?(token)
21
23
  disk_service.upload token[:key], request.body, checksum: token[:checksum]
22
- head :no_content
23
24
  else
24
25
  head :unprocessable_entity
25
26
  end
27
+ else
28
+ head :not_found
26
29
  end
27
30
  rescue ActiveStorage::IntegrityError
28
31
  head :unprocessable_entity
@@ -8,7 +8,7 @@ class ActiveStorage::RepresentationsController < ActiveStorage::BaseController
8
8
  include ActiveStorage::SetBlob
9
9
 
10
10
  def show
11
- expires_in ActiveStorage::Blob.service.url_expires_in
11
+ expires_in ActiveStorage.service_urls_expire_in
12
12
  redirect_to @blob.representation(params[:variation_key]).processed.service_url(disposition: params[:disposition])
13
13
  end
14
14
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sets the <tt>ActiveStorage::Current.host</tt> attribute, which the disk service uses to generate URLs.
4
+ # Include this concern in custom controllers that call ActiveStorage::Blob#service_url,
5
+ # ActiveStorage::Variant#service_url, or ActiveStorage::Preview#service_url so the disk service can
6
+ # generate URLs using the same host, protocol, and base path as the current request.
7
+ module ActiveStorage::SetCurrent
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ before_action do
12
+ ActiveStorage::Current.host = request.base_url
13
+ end
14
+ end
15
+ end
@@ -17,7 +17,12 @@ export class BlobRecord {
17
17
  this.xhr.setRequestHeader("Content-Type", "application/json")
18
18
  this.xhr.setRequestHeader("Accept", "application/json")
19
19
  this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
20
- this.xhr.setRequestHeader("X-CSRF-Token", getMetaValue("csrf-token"))
20
+
21
+ const csrfToken = getMetaValue("csrf-token")
22
+ if (csrfToken != undefined) {
23
+ this.xhr.setRequestHeader("X-CSRF-Token", csrfToken)
24
+ }
25
+
21
26
  this.xhr.addEventListener("load", event => this.requestDidLoad(event))
22
27
  this.xhr.addEventListener("error", event => this.requestDidError(event))
23
28
  }