From 6bec95e084877dfe81595bc1ea16b8957ce8af39 Mon Sep 17 00:00:00 2001 From: or-else Date: Thu, 7 Aug 2025 16:12:51 +0300 Subject: [PATCH] automatically change mime-type of json files to application/octeat-stream --- src/views/messages-view.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/views/messages-view.jsx b/src/views/messages-view.jsx index f6a4fd39..710f2d91 100644 --- a/src/views/messages-view.jsx +++ b/src/views/messages-view.jsx @@ -1022,6 +1022,11 @@ class MessagesView extends React.Component { const maxInbandAttachmentSize = (this.props.tinode.getServerParam('maxMessageSize', MAX_INBAND_ATTACHMENT_SIZE) * 0.75 - 1024) | 0; + // If the attachment is a JSON file, then use 'application/octet-stream' instead of 'application/json'. + // This is a temporary workaround for the collision with the 'application/json' MIME type of form responses. + // Remove this code in 2026 or so. + const jsonMimeConverter = (fileType) => fileType == 'application/json' ? 'application/octet-stream' : fileType; + if (file.size > maxInbandAttachmentSize) { // Too large to send inband - uploading out of band and sending as a link. const uploader = this.props.tinode.getLargeFileHelper(); @@ -1031,7 +1036,7 @@ class MessagesView extends React.Component { } const uploadCompletionPromise = uploader.upload(file); const msg = Drafty.attachFile(null, { - mime: file.type, + mime: jsonMimeConverter(file.type), filename: file.name, size: file.size, urlPromise: uploadCompletionPromise @@ -1042,7 +1047,7 @@ class MessagesView extends React.Component { // Small enough to send inband. fileToBase64(file) .then(b64 => this.sendMessage(Drafty.attachFile(null, { - mime: b64.mime, + mime: jsonMimeConverter(b64.mime), data: b64.bits, filename: b64.name, size: file.size