Skip to content

Commit

Permalink
Fixed handling of attachments sent from a bot.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Jun 26, 2019
1 parent 5e9a154 commit 4939199
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4939199

Please sign in to comment.