From c14032f03aba2be115d1d4206c95d9988690d222 Mon Sep 17 00:00:00 2001 From: Sittipong HAUS Date: Mon, 18 Nov 2024 19:40:52 +0700 Subject: [PATCH 1/2] fix file type missing in @hono-storage/core --- packages/core/src/file.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/file.ts b/packages/core/src/file.ts index b9c1358..30d676a 100644 --- a/packages/core/src/file.ts +++ b/packages/core/src/file.ts @@ -7,7 +7,10 @@ export class HonoStorageFile extends File { field: Field; constructor(file: File, field: Field) { - super([file], file.name); + super([file], file.name, { + type: file.type, + lastModified: file.lastModified, + }); this.field = field; } From 1649e172335fd7780f04412f72769ab7d991a790 Mon Sep 17 00:00:00 2001 From: Sittipong HAUS Date: Tue, 19 Nov 2024 04:03:00 +0700 Subject: [PATCH 2/2] feat(core): preserve File type property --- .changeset/cold-vans-tell.md | 6 ++++++ packages/core/src/file.ts | 1 - packages/core/tests/file.test.ts | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/cold-vans-tell.md diff --git a/.changeset/cold-vans-tell.md b/.changeset/cold-vans-tell.md new file mode 100644 index 0000000..db84abe --- /dev/null +++ b/.changeset/cold-vans-tell.md @@ -0,0 +1,6 @@ +--- +"@hono-storage/core": patch +--- + +feat: preserve File type property in HonoStorageFile +When a File is processed by the storage middleware, the `type` property from the original File object is now correctly inherited by HonoStorageFile. This ensures the file's content-type is maintained during file uploads. diff --git a/packages/core/src/file.ts b/packages/core/src/file.ts index 30d676a..c64febb 100644 --- a/packages/core/src/file.ts +++ b/packages/core/src/file.ts @@ -9,7 +9,6 @@ export class HonoStorageFile extends File { constructor(file: File, field: Field) { super([file], file.name, { type: file.type, - lastModified: file.lastModified, }); this.field = field; } diff --git a/packages/core/tests/file.test.ts b/packages/core/tests/file.test.ts index 5100728..4e81882 100644 --- a/packages/core/tests/file.test.ts +++ b/packages/core/tests/file.test.ts @@ -60,4 +60,17 @@ describe("HonoStorageFile", () => { expect(file.extension).toBe("zip"); }); }); + + it("should inherit type from original File", () => { + const file = new HonoStorageFile( + new File([], "sample1.txt", { + type: "text/plain", + }), + { + name: "file", + type: "single", + }, + ); + expect(file.type).toBe("text/plain"); + }); });