fix: images are not included in PDF exports (#16076)
## Description - This PR address issue https://github.com/twentyhq/twenty/issues/15998 - The issue was that images are stored as signed urls and the backend signed these with JWT - BlockNote `resolveFileUrl` uses a public CORS proxy that couldn’t access authenticated/signed URLs ## Visual Appearance https://github.com/user-attachments/assets/12936451-d91d-4371-bcf7-8a2c2bb68e9c
This commit is contained in:
+28
-1
@@ -45,7 +45,34 @@ export const exportBlockNoteEditorToPdf = async (
|
||||
initialContent: parsedBody,
|
||||
});
|
||||
|
||||
const exporter = new PDFExporter(editor.schema, pdfDefaultSchemaMappings);
|
||||
const exporter = new PDFExporter(editor.schema, pdfDefaultSchemaMappings, {
|
||||
resolveFileUrl: async (url: string) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
mode: 'cors',
|
||||
credentials: 'omit',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch asset at ${url}: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
return await response.blob();
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message.includes('Failed to fetch asset')
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to fetch asset at ${url}: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const pdfDocument = await exporter.toReactPDFDocument(editor.document);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user