fix: check the content type for the file when uploading from cloud storage (#5378)
When sending the message with audio, only the signed id of the file is sent. In the back end check only the UploadedFile type. The attachment has the default file type image, now it gets the content type from the signed id Fixes: #5375 Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -35,7 +35,13 @@ class Messages::MessageBuilder
|
||||
file: uploaded_attachment
|
||||
)
|
||||
|
||||
attachment.file_type = file_type(uploaded_attachment&.content_type) if uploaded_attachment.is_a?(ActionDispatch::Http::UploadedFile)
|
||||
attachment.file_type = if uploaded_attachment.is_a?(String)
|
||||
file_type_by_signed_id(
|
||||
uploaded_attachment
|
||||
)
|
||||
else
|
||||
file_type(uploaded_attachment&.content_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@ module FileTypeHelper
|
||||
:file
|
||||
end
|
||||
|
||||
# Used in case of DIRECT_UPLOADS_ENABLED=true
|
||||
def file_type_by_signed_id(signed_id)
|
||||
blob = ActiveStorage::Blob.find_signed(signed_id)
|
||||
file_type(blob&.content_type)
|
||||
end
|
||||
|
||||
def image_file?(content_type)
|
||||
[
|
||||
'image/jpeg',
|
||||
|
||||
Reference in New Issue
Block a user