Rendering report with image sometimes takes to long
-
I have a report which shows single or multiple person photos in it, the problem is that I pass the image URL in <img> tag some time the server the image is stored on is down and the report takes time waiting to access the server, is there any timeout for solving this issue in configurations?
-
https://playground.jsreport.net/w/jan_blaha/HUNmlyBw
You could implement a custom helper converting url to base64 that aborts image download after some time.
const jsreport = require('jsreport-proxy') const axios = await jsreport.npm.require('axios@0.25.0') async function imageToDataURIWithTimeout(url) { try { const response = await axios.get(url, { responseType: 'arraybuffer', timeout: 100 }) const base64 = Buffer.from(response.data, 'binary').toString('base64') return 'data:image/jpg;base64,' + base64 } catch (e) { return 'some placeholder image maybe' } }
<img src={{imageToDataURIWithTimeout "https://jsreport.net/img/home.jpg"}} />