Skip to content

Commit 656d8c8

Browse files
committed
create component from blob
1 parent ea6c877 commit 656d8c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ export class Component implements Part {
5454
return new Component(file.type.length > 0 ? {"Content-Type": file.type} : {}, await file.arrayBuffer());
5555
}
5656

57+
/**
58+
* Create a Component from a {@link !Blob}. If blob media type is available,
59+
* it will be set in the `Content-Type` header. The blob's contents will be used as the part's body.
60+
*
61+
* This method might be slow if a large file is provided as the blob contents need to be read.
62+
*
63+
* @param blob Blob to create the component from
64+
*/
65+
public static async blob(blob: Blob) {
66+
return new Component(blob.type.length > 0 ? {"Content-Type": blob.type} : {}, await blob.arrayBuffer());
67+
}
68+
5769
public bytes(): Uint8Array {
5870
const result: ArrayLike<number>[] = [];
5971
for (const [key, value] of this.headers.entries())

0 commit comments

Comments
 (0)