How missing image/ failed download image for docxImage



  • Hi,

    I would like to ask if there is any feature that to put a red cross for the image in docx in case the URL is invalid or if there is issue in downloading the image. Right now if any one image encounter that, it throws and error and the full report generation failed. Its quite difficult to troubleshoot which image encounter the issue as well.



  • You can implement a custom helper, that will check the existence of the remote image and fall-back into a custom image if it cannot reach it.

    const jsreport = require('jsreport-proxy')
    const fallbackImgSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK8AAAAtCAIAAABXiKzxAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAgdSURBVHhe7Zj9T1NXGMeX/brsD1iWJZtZtv2wDbVoeRNqQUFaaXlTQJGIjGWmugW2xfoSDA6WaRHHL84tEzZXnNJoeNFVnVQddQhVpC6jikuj7iaGGg3l7fJ2u3PPObf3lRYEEmTnk/7Afc5zzrnP83w5L/clFYHAQdRA4CFqIPAQNRB4iBoIPEQNBB6iBgIPUQOBh6iBwEPUQOAhaiDwEDUQeIgaCDxzpoaCgoL6+vqurq7e3t47d+40Njbu2LFjxYoVuJnwIjAHatBoNC0tLQElXC6X0WjEfoQFz2zVoNVqwUqAi69En8+Xk5ODvQkLm+dXg1qtXhWfcOHiJVz2QKCnp8disezcubO8vLy9vR1bA4F7vb3xCQm42/SxOH2039NUjB9faEw2t4+GyaAcJdi2AHkeNSQb0nWH618/+XdOWx/DMDDIQENDw8qVK7EHBCgDNQG+qjmKrdPH6gb5oxxm/PgCU+b0gRz4KZfDbq8tw8aFyIzVkF2y99XmJ69cGHj5/MBpahwVu7u7WyIFxNmzZ5HDH3cfLI+KxdZFR5MXhOhtwk8yzKwYaHctflzAzEwNEQWfvtE6+NrlwSWND3WVP3j+fYyKfeDAAewhBlw0kMPQREC9q3pZbDxuWFyEUYPF5Qcrg8uCHxcwM1DD8ui49073vNU6pG74S7s2OTo6+vFjrIbCwkLsJCYpKam/vx84gO3E2DnyZuOj94t24bawSJKoN1tdFLBA/D6Pv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faEjvH0GwNxyTps4jh06BCYEDAwMHDmzJngcVICTdOVlZW4DyS2tHJN57ihlYqNi8OmqRBGyR7GBEc0vRkWSHBuEIaKl120C8uQp2px7hRzrYaNW4sSXRMZXWMJxg3YBBF+ZAR0dnYmJibW1dVRFDU5OYmMT548aW5uzs7Oxn041py8kXxzIuOkEz+HQBil1QPG5G4FLDB9qFGeDTM8RvmcgkuVyWa3oTMHTBVwD7ahI+YMTpGiuVhmpoZpnSLFc0hNehubD2yQ+8+LGjTaxJSrPuPtyaRv+UNfVVUVmEpIR0cHaoqMjNTpdLm5uQaDQfFYoCk/lg5Gc01uKtmNTSEQRYnyhe9k+M5Iu2tkfgicXtrngdsFusP5XTUFoA2mKtjmcHO3eq784W+YsrRCBdGUi9uMJMg7iaJRvGFK5oAziC/FQR+5/7yoAZBXdXzdLSa7m1n346WYAtPnh4/C9+AZZQL7jp1Iyy/MKtqesfVjw5ZthvxC45Zt4G9gwb9tn2z+sizt1/asbib9NrPpl8t49NBIohR9r6FBYrhPRkrZk7jDj1V4n4Gpohyz+vokTavJ5kGDgfUImwQodQr/9Uk8B/CH/wGcu4Mvr9x/vtQQFR2db2013GYyu5nP7jI03gcw40zgyINAyi0mtYvRhfyt72I2uJmNbialrjV21fS+T0+R+dkiTxWBI4waAGDNz9t3UH/uXnnPEBIBYmxi4si9wYyOwfybQ2F/m9ufZto6taY9YDvB44YFqoFyKCy9s4KoYWrCqyHIulTd/fv3kRTATdK8Z49mtXZtcsp0fgkaDR5lWpTV4q/P+GgwlxA1TM0M1ABIS0s7derU+fPni4qKsGlegBUDu7BbsqHPBUQNUzMzNRAWN0QNBB6iBgIPUQOBh6iBwEPUQOAhaiDwEDUQeIgaCDxEDQQeogYCh0r1H3rynmXRZBCKAAAAAElFTkSuQmCC'
    const axios = await jsreport.npm.require('axios@0.27.2')
    async function docxImageWithFallback(options) {   
        try {        
            await axios.get(options.hash.src)
            return docxImage(options)
        } catch (e) {        
            options.hash.src = fallbackImgSrc
            return docxImage(options)
        }
    }
    

    https://playground.jsreport.net/w/anon/2R6FUdOX


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.