fix: embed dropped images as data URLs and prevent duplicate attachment #163
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user