docxImage base64 image not working
-
Hi @jan_blaha
I'm trying to use docxImage in docx recipe.
https://playground.jsreport.net/w/Heplinesss_17/kp_dMlTAIn above demo it is throwing error while docxImage helper call
If you can help me with that will be great!
Thanks
-
Your image is linked with
{{docxImage src=client.logoUrl}}
, but the input data isstudents:[]
array. So theclient.logoUrl
doesn't get resolved. Maybe you want to loop?
-
I'm using below script for convert image into base64 and I've used loop as well but it's not working.
const axios = require('axios'); function getBase64(url) { let base64Url; if (url) { base64Url = axios .get(url, { responseType: 'arraybuffer', }) .then((response) => { const base64 = Buffer.from(response.data, 'binary').toString('base64'); return `data:image/png;base64,${base64}` }); } return base64Url; } async function beforeRender(req) { await Promise.all( req.data.students.map(async (student) => { student.client.logo = await getBase64( student.client.logoUrl, ); }), ); }
I just want to use image and it is not working directly you can check here https://playground.jsreport.net/w/Heplinesss_17/na5_KSV0
Thanks!
-
I just want to use image and it is not working directly you can check here https://playground.jsreport.net/w/Heplinesss_17/na5_KSV0
Interesting issue. The server hosting the image you use returns Content-Type header
image/png; qs=0.7
which seems to be invalid based on the standard. If you use an image which returns valid content typeimage/png
, it will work https://playground.jsreport.net/w/anon/7Vf5GSb6
-
interesting, technically the content type
image/png; qs=0.7
is not in the common format but it is valid, thatqs
is used in content negotiation, so now not sure if we should just relax the content type check to allow such parameters along the content type.
-
I see, I found some article about that it isn't standard, but it seems it really is. It will be fixed in jsreport v3.
-
Hey @jan_blaha @bjrmatos
So, Is there any solution to allow these type of images in docxImage? I've tried to convert them into base64 but the function is not working for docxImage.
https://playground.jsreport.net/w/Heplinesss_17/kp_dMlTAThanks!
-
Please check this
https://playground.jsreport.net/w/anon/NySKRofa
-
Thanks! @jan_blaha