File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,19 @@ export class Multipart implements Part {
231231 return Multipart . parseBody ( part . bytes ( ) , new TextEncoder ( ) . encode ( boundary ) , mediaType ?? void 0 ) ;
232232 }
233233
234+ /**
235+ * Create Multipart from a {@link !Blob}. The boundary and media type are determined from the blob's type.
236+ * @param blob The blob
237+ * @throws {@link !SyntaxError } If the `Content-Type` header is missing or does not include a boundary
238+ */
239+ public static async blob ( blob : Blob ) : Promise < Multipart > {
240+ const type = blob . type ;
241+ if ( type === "" ) throw new SyntaxError ( "Blob is missing Content-Type header" ) ;
242+ const { mediaType, boundary} = Multipart . parseContentType ( type ) ;
243+ if ( boundary === null ) throw new SyntaxError ( "Missing boundary in Content-Type header of blob" ) ;
244+ return Multipart . parseBody ( new Uint8Array ( await blob . arrayBuffer ( ) ) , new TextEncoder ( ) . encode ( boundary ) , mediaType ?? void 0 ) ;
245+ }
246+
234247 /**
235248 * Create Multipart from {@link FormData}.
236249 * This method might be slow if the form data contains large files.
You can’t perform that action at this time.
0 commit comments