File tree Expand file tree Collapse file tree 8 files changed +42
-32
lines changed
test/controllers/representations Expand file tree Collapse file tree 8 files changed +42
-32
lines changed Original file line number Diff line number Diff line change @@ -89,9 +89,6 @@ Layout/EmptyLinesAroundModuleBody:
89
89
Style/HashSyntax :
90
90
Enabled : true
91
91
92
- Layout/FirstArgumentIndentation :
93
- Enabled : true
94
-
95
92
# Method definitions after `private` or `protected` isolated calls need one
96
93
# extra level of indentation.
97
94
Layout/IndentationConsistency :
Original file line number Diff line number Diff line change
1
+ * Add ` ActiveStorage::Streaming ` module that can be included in a controller to get access to ` #send_blob_stream ` ,
2
+ which wraps the new ` ActionController::Base#send_stream ` method to stream a blob from cloud storage:
3
+
4
+ ``` ruby
5
+ class MyPublicBlobsController < ApplicationController
6
+ include ActiveStorage ::SetBlob , ActiveStorage ::Streaming
7
+
8
+ def show
9
+ http_cache_forever(public: true ) do
10
+ send_blob_stream @blob , disposition: params[:disposition ]
11
+ end
12
+ end
13
+ end
14
+ ```
15
+
16
+ * DHH *
17
+
1
18
* Add ability to use pre- defined variants.
2
19
3
20
` ` ` ruby
Original file line number Diff line number Diff line change 2
2
3
3
# The base class for all Active Storage controllers.
4
4
class ActiveStorage ::BaseController < ActionController ::Base
5
- include ActiveStorage ::SetCurrent
5
+ include ActiveStorage ::SetCurrent , ActiveStorage :: Streaming
6
6
7
7
protect_from_forgery with : :exception
8
8
9
9
self . etag_with_template_digest = false
10
-
11
- private
12
- def stream ( blob )
13
- blob . download do |chunk |
14
- response . stream . write chunk
15
- end
16
- ensure
17
- response . stream . close
18
- end
19
10
end
Original file line number Diff line number Diff line change 3
3
# Proxy files through application. This avoids having a redirect and makes files easier to cache.
4
4
class ActiveStorage ::Blobs ::ProxyController < ActiveStorage ::BaseController
5
5
include ActiveStorage ::SetBlob
6
- include ActiveStorage ::SetHeaders
7
6
8
7
def show
9
8
http_cache_forever public : true do
10
- set_content_headers_from @blob
11
- stream @blob
9
+ send_blob_stream @blob
12
10
end
13
11
end
14
12
end
Original file line number Diff line number Diff line change 3
3
# Proxy files through application. This avoids having a redirect and makes files easier to cache.
4
4
class ActiveStorage ::Representations ::ProxyController < ActiveStorage ::BaseController
5
5
include ActiveStorage ::SetBlob
6
- include ActiveStorage ::SetHeaders
7
6
8
7
def show
9
8
http_cache_forever public : true do
10
- set_content_headers_from representation . image
11
- stream representation
9
+ send_blob_stream representation . image
12
10
end
13
11
end
14
12
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveStorage ::Streaming
4
+ DEFAULT_BLOB_STREAMING_DISPOSITION = "inline"
5
+
6
+ include ActionController ::Live
7
+
8
+ private
9
+ # Stream the blob from storage directly to the response. The disposition can be controlled by setting +disposition+.
10
+ # The content type and filename is set directly from the +blob+.
11
+ def send_blob_stream ( blob , disposition : nil ) #:doc:
12
+ send_stream (
13
+ filename : blob . filename . sanitized ,
14
+ disposition : blob . forced_disposition_for_serving || disposition || DEFAULT_BLOB_STREAMING_DISPOSITION ,
15
+ type : blob . content_type_for_serving ) do |stream |
16
+ blob . download do |chunk |
17
+ stream . write chunk
18
+ end
19
+ end
20
+ end
21
+ end
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ class ActiveStorage::Representations::ProxyControllerWithPreviewsTest < ActionDi
48
48
49
49
assert_predicate @blob . preview_image , :attached?
50
50
51
- image = read_image ( @blob . preview_image . variant ( resize : "100x100" ) )
51
+ image = read_image ( @blob . preview_image . variant ( resize : "100x100" ) . processed )
52
52
assert_equal 77 , image . width
53
53
assert_equal 100 , image . height
54
54
end
You can’t perform that action at this time.
0 commit comments