mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-15 09:31:21 +00:00
Fix: fall back to document attachment when HEIC decode fails
The in-browser HEIC decoder (heic2any, libheif WASM) does not support every HEVC variant — e.g. iPhone photos use HEVC Main 10, which fails with 'format not supported'. Previously the rejection was unhandled and the file disappeared with no attachment and no error. Now a failed conversion shows an error toast and attaches the original file as a document, so nothing is lost.
This commit is contained in:
parent
c7429e88a4
commit
595dbd2dea
2 changed files with 27 additions and 4 deletions
|
|
@ -458,16 +458,15 @@
|
|||
}
|
||||
return imageUrl;
|
||||
};
|
||||
const imageFile = isHeicImage(file) ? await convertHeicToJpeg(file) : file;
|
||||
const imageUrl = await new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => resolve(reader.result as string);
|
||||
reader.onerror = () => reject(reader.error);
|
||||
reader.readAsDataURL(imageFile);
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
const compressed = await compressImageHandler(imageUrl, $settings, $config);
|
||||
const blob = await (await fetch(compressed as string)).blob();
|
||||
return new File([blob], imageFile.name, { type: imageFile.type });
|
||||
return new File([blob], file.name, { type: file.type });
|
||||
};
|
||||
|
||||
const uploadFileHandler = async (file: File, process = true, prepareImage = false) => {
|
||||
|
|
@ -475,6 +474,17 @@
|
|||
const targetQueueKey = queueKey;
|
||||
const senderId = $user?.id;
|
||||
const tempItemId = uuidv4();
|
||||
|
||||
// Convert HEIC up front so a decode failure can fall back to a
|
||||
// document attachment instead of dropping the file.
|
||||
if (prepareImage && isHeicImage(file)) {
|
||||
try {
|
||||
file = await convertHeicToJpeg(file);
|
||||
} catch (error) {
|
||||
console.error('Failed to convert HEIC to JPEG', error);
|
||||
toast.error($i18n.t("Couldn't display this HEIC image, attaching it as a document instead"));
|
||||
}
|
||||
}
|
||||
const fileItem: any = {
|
||||
type: 'file',
|
||||
file: '',
|
||||
|
|
|
|||
|
|
@ -1335,7 +1335,20 @@
|
|||
return imageUrl;
|
||||
};
|
||||
|
||||
const imageFile = isHeicImage(file) ? await convertHeicToJpeg(file) : file;
|
||||
let imageFile = file;
|
||||
if (isHeicImage(file)) {
|
||||
try {
|
||||
imageFile = await convertHeicToJpeg(file);
|
||||
} catch (error) {
|
||||
// The in-browser HEIC decoder (heic2any/libheif WASM) does not
|
||||
// support every HEVC variant (e.g. iPhone Main 10). Attach the
|
||||
// original file as a document instead of dropping it.
|
||||
console.error('Failed to convert HEIC to JPEG', error);
|
||||
toast.error($i18n.t("Couldn't display this HEIC image, attaching it as a document instead"));
|
||||
uploadFileHandler(file, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let reader = new FileReader();
|
||||
|
||||
reader.onload = async (event) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue