Fix image uploads using the wrong format (#2380)

* fix(app): preserve image attachment MIME types

Image intake discarded clipboard and desktop path metadata, then guessed JPEG when a later file object had no type. Resolve MIME once at the platform boundary and require it downstream.

* fix(app): honor native picker MIME metadata
This commit is contained in:
Mohamed Boudra
2026-07-24 21:11:41 +08:00
committed by GitHub
parent 967edab497
commit 21597bdc1b
13 changed files with 198 additions and 54 deletions
@@ -5,9 +5,9 @@ import type { ImageAttachment } from "@/composer/types";
import { getDesktopHost } from "@/desktop/host";
import { persistAttachmentFromBlob, persistAttachmentFromFileUri } from "@/attachments/service";
import {
getRasterImageMimeTypeFromPath,
isRasterImageFile,
isRasterImagePath,
resolveRasterImageMimeType,
} from "@/attachments/file-types";
import { isWeb } from "@/constants/platform";
import type { DroppedItem, DroppedPathItem, FileDropSink } from "./types";
@@ -27,14 +27,21 @@ interface DesktopDragDropEvent {
}
async function filePathToImageAttachment(path: string): Promise<ImageAttachment> {
const mimeType = getRasterImageMimeTypeFromPath(path) ?? "image/jpeg";
const mimeType = resolveRasterImageMimeType({ path });
if (!mimeType) {
throw new Error(`Unsupported image type for '${path}'.`);
}
return await persistAttachmentFromFileUri({ uri: path, mimeType });
}
async function fileToImageAttachment(file: File): Promise<ImageAttachment> {
const mimeType = resolveRasterImageMimeType({ mimeType: file.type, path: file.name });
if (!mimeType) {
throw new Error(`Unsupported image type for '${file.name}'.`);
}
return await persistAttachmentFromBlob({
blob: file,
mimeType: file.type || "image/jpeg",
mimeType,
fileName: file.name,
});
}