Skip to content

Commit d14fb0f

Browse files
fix: handle ReadableStream attachments correctly in form data
1 parent 6469f34 commit d14fb0f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/resources/messages.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,9 @@ export class Messages extends Resource {
334334
type: attachment.contentType,
335335
});
336336
} else if (attachment.content instanceof ReadableStream) {
337-
// For ReadableStream, we need to read it into a buffer first
338-
const chunks: Buffer[] = [];
339-
const reader = attachment.content.getReader();
340-
let result = await reader.read();
341-
while (!result.done) {
342-
chunks.push(Buffer.from(result.value));
343-
result = await reader.read();
344-
}
345-
const buffer = Buffer.concat(chunks);
346-
file = new File([buffer], attachment.filename, {
347-
type: attachment.contentType,
348-
});
337+
// For ReadableStream, append it directly to the form
338+
form.append(contentId, attachment.content, attachment.filename);
339+
continue;
349340
} else {
350341
throw new Error('Unsupported attachment content type');
351342
}

0 commit comments

Comments
 (0)