Skip to content

Commit 5a89449

Browse files
Merge pull request #58 from DBB-Software/feat/PLATFORM-1979
feat: updating getting content-type of the file during upload to s3
2 parents 5baace9 + 939b5c7 commit 5a89449

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/express": "5.0.0",
4343
"@types/jest": "29.5.14",
4444
"@types/lodash": "4.17.13",
45+
"@types/mime-types": "2.1.4",
4546
"@types/node": "20.12.11",
4647
"@types/yargs": "17.0.32",
4748
"@typescript-eslint/eslint-plugin": "7.1.0",
@@ -78,6 +79,7 @@
7879
"esbuild": "0.21.4",
7980
"express": "4.21.2",
8081
"lodash": "4.17.21",
82+
"mime-types": "2.1.35",
8183
"yargs": "17.7.2"
8284
},
8385
"peerDependencies": {

src/common/aws.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as AWS from 'aws-sdk'
66
import { partition } from '@aws-sdk/util-endpoints'
77
import fs from 'node:fs'
88
import path from 'node:path'
9+
import mime from 'mime-types'
910

1011
type GetAWSBasicProps =
1112
| {
@@ -46,18 +47,7 @@ export const getSTSIdentity = async (props: GetAWSBasicProps) => {
4647
export const getFileContentType = (filePath?: string) => {
4748
if (!filePath) return
4849

49-
const extension = path.extname(filePath)
50-
51-
switch (extension) {
52-
case '.css':
53-
return 'text/css'
54-
case '.js':
55-
return 'application/javascript'
56-
case '..html':
57-
return 'text/html'
58-
default:
59-
return 'application/octet-stream'
60-
}
50+
return mime.lookup(filePath) || 'application/octet-stream'
6151
}
6252

6353
export const uploadFileToS3 = async (s3Client: S3, options: PutObjectCommandInput) => {

0 commit comments

Comments
 (0)