From 8a1d7c5a58852fdc944c9451f708e6054c0c22f1 Mon Sep 17 00:00:00 2001 From: Tony Anziano Date: Wed, 26 Jun 2019 16:44:34 -0700 Subject: [PATCH] Fixed handling of attachments sent from a bot. --- CHANGELOG.md | 1 + .../core/src/attachments/middleware/getAttachment.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 549354faa..9f4d31f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed - [client/main] Auto update is now opt-in by default and changed UX to reflect this in PR [1575](https://github.com/microsoft/BotFramework-Emulator/pull/1575) - [client/main] Fixed OAuth card sign-in flow when not using magic code in PR [1660](https://github.com/microsoft/BotFramework-Emulator/pull/1660) +- [client/main] Fixed issue where images uploaded from the bot weren't being handled properly in PR [1661](https://github.com/microsoft/BotFramework-Emulator/pull/1661) ## v4.4.2 - 2019 - 05 - 28 ## Fixed diff --git a/packages/emulator/core/src/attachments/middleware/getAttachment.ts b/packages/emulator/core/src/attachments/middleware/getAttachment.ts index a6f88355a..bfe1e66bb 100644 --- a/packages/emulator/core/src/attachments/middleware/getAttachment.ts +++ b/packages/emulator/core/src/attachments/middleware/getAttachment.ts @@ -52,7 +52,12 @@ export default function getAttachment(bot: BotEmulator) { const attachmentBase64 = parms.viewId === 'original' ? attachment.originalBase64 : attachment.thumbnailBase64; if (attachmentBase64) { - const buffer = Buffer.from(Buffer.from(attachmentBase64.buffer as ArrayBuffer).toString(), 'base64'); + // can be an ArrayBuffer if uploaded via the Web Chat paperclip control, or can be + // an already-encoded base64 content string if sent from the bot + const bufferContents = attachmentBase64.buffer + ? Buffer.from(attachmentBase64.buffer as ArrayBuffer).toString() + : attachmentBase64.toString(); + const buffer = Buffer.from(bufferContents, 'base64'); res.contentType = attachment.type; res.send(HttpStatus.OK, buffer);