Skip to content

Commit

Permalink
Merge pull request #71 from sngmn451/main
Browse files Browse the repository at this point in the history
fix file type missing in @hono-storage/core
  • Loading branch information
sor4chi authored Nov 18, 2024
2 parents 0951c13 + 1649e17 commit bec4ed6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/cold-vans-tell.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/core/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export class HonoStorageFile extends File {
field: Field;

constructor(file: File, field: Field) {
super([file], file.name);
super([file], file.name, {
type: file.type,
});
this.field = field;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/core/tests/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit bec4ed6

Please sign in to comment.