Skip to content
File

Blob: src/shared/web/mime.ts

typescript32 lines
1/**
2 * Guess a Content-Type from a filename based on extension.
3 * This is used for inline media preview in the UI (images, PDFs, etc.).
4 * Defaults to application/octet-stream when unknown.
5 */
6export function getContentTypeFromName(name: string): string {
7 const ext = (name.split(".").pop() || "").toLowerCase();
8 switch (ext) {
9 case "png":
10 return "image/png";
11 case "jpg":
12 case "jpeg":
13 return "image/jpeg";
14 case "gif":
15 return "image/gif";
16 case "webp":
17 return "image/webp";
18 case "bmp":
19 return "image/bmp";
20 case "ico":
21 return "image/x-icon";
22 case "svg":
23 return "image/svg+xml";
24 case "pdf":
25 return "application/pdf";
26 case "txt":
27 return "text/plain; charset=utf-8";
28 default:
29 return "application/octet-stream";
30 }
31}