Skip to content

Commit 25b755e

Browse files
committed
accept blob as file at objects.put method
1 parent 3f5c7b8 commit 25b755e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.changeset/ninety-tips-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/blob": patch
3+
---
4+
5+
Accept JavaScript Blob as file at `objects.put` method

src/managers/objects.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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);

src/schemas/put.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { nameLikeSchema } from "./common";
44
export 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. */

0 commit comments

Comments
 (0)