Files
paseo/packages/app/src/hooks/image-attachment-picker.native.ts
T
Mohamed BoudraandGitHub 21597bdc1b 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
2026-07-24 21:11:41 +08:00

42 lines
1.2 KiB
TypeScript

import { ImageManipulator, SaveFormat } from "expo-image-manipulator";
import {
normalizePickedImageAssetsWith,
type ExpoImagePickerAssetLike,
type PickedImageAttachmentInput,
} from "./picked-image-normalizer";
export type {
ExportPickedImageAsPng,
ExpoImagePickerAssetLike,
PickedImageAttachmentInput,
PickedImageSource,
} from "./picked-image-normalizer";
async function exportPickedImageAsPng(uri: string): Promise<string> {
const context = ImageManipulator.manipulate(uri);
let image: Awaited<ReturnType<typeof context.renderAsync>> | null = null;
try {
image = await context.renderAsync();
const result = await image.saveAsync({
format: SaveFormat.PNG,
});
return result.uri;
} finally {
image?.release();
context.release();
}
}
export async function normalizePickedImageAssets(
assets: readonly ExpoImagePickerAssetLike[],
): Promise<PickedImageAttachmentInput[]> {
return normalizePickedImageAssetsWith(assets, exportPickedImageAsPng);
}
export async function pickImagesWithDesktopDialog(
_dialog?: unknown,
): Promise<PickedImageAttachmentInput[]> {
throw new Error("Desktop dialog API is not available on native.");
}