Files
payloadcms/test/uploads/getMimeType.ts
2024-04-16 09:22:41 -04:00

33 lines
530 B
TypeScript

import path from 'path'
export const getMimeType = (
filePath: string,
): {
filename: string
type: string
} => {
const ext = path.extname(filePath).slice(1)
let type: string
switch (ext) {
case 'png':
type = 'image/png'
break
case 'jpg':
type = 'image/jpeg'
break
case 'jpeg':
type = 'image/jpeg'
break
case 'svg':
type = 'image/svg+xml'
break
default:
type = 'image/png'
}
return {
filename: path.basename(filePath),
type,
}
}