From ef79b2aa9be0a0d9cdb3bab3190a7682be6f0a4f Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 8 Oct 2023 11:55:56 -0700 Subject: [PATCH] Bugfix with file sending --- src/App.vue | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index 120ffa0..8ab2abf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2657,6 +2657,14 @@ export default { // The image upload button handler. uploadFile() { + // Prepare the message now so the channel name will be correct, + // in case they upload a fat file and switch to a wrong channel + // before the data is ready to send. + let msg = { + action: "file", + channel: this.channel, + }; + let input = document.createElement('input'); input.type = 'file'; input.accept = 'image/*'; @@ -2681,12 +2689,10 @@ export default { fileByteArray.push(u8array[i]); } - let msg = JSON.stringify({ - action: "file", - channel: this.channel, - message: file.name, - bytes: fileByteArray, //btoa(fileByteArray), - }); + // Attach the file to the message. + msg.message = file.name; + msg.bytes = fileByteArray; + msg = JSON.stringify(msg); // Send it to the chat server. this.ws.conn.send(msg);