Skip to content

Commit edb8ccb

Browse files
committed
Download blob from DB and send_data from attachments#show
1 parent e629130 commit edb8ccb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1+
# frozen_string_literal: true
2+
13
class AttachmentsController < ApplicationController
4+
skip_forgery_protection
5+
26
def show
7+
if (key = decode_verified_key)
8+
send_data ActiveStorage::Blob.service.download(key[:key]), content_type: key[:content_type], disposition: key[:disposition]
9+
else
10+
head :not_found
11+
end
12+
rescue Errno::ENOENT
13+
head :not_found
14+
end
15+
16+
private
17+
18+
def decode_verified_key
19+
key = ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
20+
key&.deep_symbolize_keys
321
end
422
end

0 commit comments

Comments
 (0)