fix: embed dropped images as data URLs and prevent duplicate attachment #163

This commit is contained in:
Linus Rath
2026-04-09 19:50:42 +02:00
parent d0cc439fd1
commit f19aaf6207
2 changed files with 13 additions and 11 deletions
+12 -11
View File
@@ -532,17 +532,18 @@ export function EmailComposer({
} }
}, [client, t]); }, [client, t]);
const handleImageUpload = useCallback(async (file: File): Promise<string | null> => { const handleImageUpload = useCallback((file: File): Promise<string | null> => {
if (!client) return null; return new Promise((resolve) => {
try { const reader = new FileReader();
const { blobId } = await client.uploadBlob(file); reader.onload = (e) => resolve((e.target?.result as string) ?? null);
return await client.fetchBlobAsObjectUrl(blobId, file.name, file.type); reader.onerror = () => {
} catch (error) { debug.error(`Failed to read inline image ${file.name}`);
debug.error(`Failed to upload inline image ${file.name}:`, error); toast.error(t('upload_failed', { filename: file.name }));
toast.error(t('upload_failed', { filename: file.name })); resolve(null);
return null; };
} reader.readAsDataURL(file);
}, [client, t]); });
}, [t]);
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => { const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
if (!event.target.files) return; if (!event.target.files) return;
+1
View File
@@ -118,6 +118,7 @@ export function RichTextEditor({
); );
if (imageFiles.length === 0) return false; if (imageFiles.length === 0) return false;
event.preventDefault(); event.preventDefault();
event.stopPropagation();
for (const file of imageFiles) { for (const file of imageFiles) {
upload(file).then((url) => { upload(file).then((url) => {
if (url) { if (url) {