forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ActiveStorage::Streaming so your own controllers can use it (r…
…ails#41440) Extract ActiveStorage::Streaming so your own controller can use it
- Loading branch information
Showing
8 changed files
with
42 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
activestorage/app/controllers/concerns/active_storage/set_headers.rb
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
activestorage/app/controllers/concerns/active_storage/streaming.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveStorage::Streaming | ||
DEFAULT_BLOB_STREAMING_DISPOSITION = "inline" | ||
|
||
include ActionController::Live | ||
|
||
private | ||
# Stream the blob from storage directly to the response. The disposition can be controlled by setting +disposition+. | ||
# The content type and filename is set directly from the +blob+. | ||
def send_blob_stream(blob, disposition: nil) #:doc: | ||
send_stream( | ||
filename: blob.filename.sanitized, | ||
disposition: blob.forced_disposition_for_serving || disposition || DEFAULT_BLOB_STREAMING_DISPOSITION, | ||
type: blob.content_type_for_serving) do |stream| | ||
blob.download do |chunk| | ||
stream.write chunk | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters