File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @squarecloud/blob " : patch
3+ ---
4+
5+ Accept JavaScript Blob as file at ` objects.put ` method
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export class BlobObjectsManager {
4040 const file = await this . parseFile ( payload . file ) ;
4141
4242 const formData = new FormData ( ) ;
43- formData . append ( "file" , new Blob ( [ file ] ) ) ;
43+ formData . append ( "file" , file instanceof Blob ? file : new Blob ( [ file ] ) ) ;
4444
4545 const { response } = await this . client . api . request < PutObjectResponse > (
4646 "put" ,
@@ -71,8 +71,8 @@ export class BlobObjectsManager {
7171 return response . status === "success" ;
7272 }
7373
74- private async parseFile ( file : string | Buffer ) {
75- let result : Buffer | undefined ;
74+ private async parseFile ( file : string | Buffer | Blob ) {
75+ let result : Buffer | Blob | undefined ;
7676
7777 if ( typeof file === "string" ) {
7878 result = await readFile ( file ) . catch ( ( ) => undefined ) ;
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { nameLikeSchema } from "./common";
44export const putObjectSchema = z . object ( {
55 /** A string representing the name for the file. */
66 name : nameLikeSchema ,
7- /** Use absolute path or Buffer, can be a single file or compressed (zip) */
8- file : z . string ( ) . or ( z . instanceof ( Buffer ) ) ,
7+ /** Use absolute path, Buffer or Blob */
8+ file : z . string ( ) . or ( z . instanceof ( Buffer ) ) . or ( z . instanceof ( Blob ) ) ,
99 /** A string representing the prefix for the file. */
1010 prefix : nameLikeSchema . optional ( ) ,
1111 /** A number indicating the expiration period of the file, ranging from 1 to 365 days. */
You can’t perform that action at this time.
0 commit comments