Skip to content

Commit

Permalink
fix: add new file upload name and content type
Browse files Browse the repository at this point in the history
  • Loading branch information
Theryston committed Feb 15, 2024
1 parent 1c7db40 commit 9357b9c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/proud-buttons-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"jsx-mail": patch
"@jsx-mail/core": patch
---

new file upload name and content type
Binary file modified bun.lockb
Binary file not shown.
9 changes: 6 additions & 3 deletions packages/core/src/cloud/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ export async function uploadFile({ path: filePath, originalPath }: StorageData):
try {
const file = readRawFile(filePath);
const form = new formData();
form.append('file', file);

const fileName = path.basename(originalPath);
const mimeType = getFileMimetype(filePath);

form.append('_jsxmail_mimetype', mimeType);
form.append('_jsxmail_originalname', fileName);
form.append('file', file, {
filename: fileName,
contentType: mimeType,
});


const response = await client.post('/file', form, {
headers: form.getHeaders(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export async function transformChildrenFileToPath(folderPath: string) {
}

export function getFileMimetype(filePath: string) {
return mime.lookup(filePath);
return mime.lookup(filePath) || undefined;
}

export async function createFileWithFolder(
Expand Down
2 changes: 1 addition & 1 deletion packages/jsx-mail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@jsx-mail/core": "workspace:*",
"axios": "^1.6.7",
"chokidar": "^3.5.3",
"dotenv": "^16.3.1",
"dotenv": "^16.4.4",
"express": "^4.18.2",
"gluegun": "^5.1.6",
"json5": "^2.2.3",
Expand Down

0 comments on commit 9357b9c

Please sign in to comment.