How to modify the config of jsreport-client using #assets resources



  • I am trying to display static images on the report. And I am trying to use the assets to achieve.

    I added <img src="{#asset ../assets/GVC/img/logo.png @encoding=dataURI}"/> into my html template.

    And in my client render, I added the followings.

    client.render({
          template: {
            content: ReadGVCContent("pdf_outside.html"),
            recipe: "chrome-pdf",
            engine: "handlebars",
            helpers: ``,
          },
          data: data,
          options: {
            extensions: {
              assets: {
                allowedFiles: "assets/*"
              }
            }
          }
        })
    

    I have also tried to add the options into the jsreport app too.

    const jsreport = require('jsreport')({
      extensions: {
        express: {
          app: reportingApp,
          server: server
        },
        assets: {
          allowedFiles: "assets/*",   
          searchOnDiskIfNotFoundInStore: false,
          rootUrlForLinks: "http://localhost/",
          publicAccessEnabled: true
        }
      },
      appPath: "/reporting"
    });
    

    But it keeps complaint on
    Error: Request to file C:\workspace\js_workspace\pdf_generator\assets\GVC\img\logo.png denied. Please allow it by setting config { "assets": { "allowedFiles": "**/foo.js" } }

    the logo.png is already in the right place
    .../pdf_generator/assets/GVC/img/logo.png

    It seems to be mis-setting of options, does anyone know how to do the config in a right way? Thanks.



    • the configuration for extensions cannot be passed in request call, it is server global, so only the second snipped is correct way

    • you should set searchOnDiskIfNotFoundInStore: true because your logo.png is plain file and not an asset entity

    • your glob assets/* is not good enough, it should be assets/**, see the docs
      https://github.com/isaacs/node-glob#glob-primer



  • Thx for the clarification,
    I found that using #asset on the "jsreport-client", needed to be modify the config in the jsreportapp (PORT:5488 one) called "jsreport.config.json".
    Then, declaring the the assets option like jan_blaha said.

    And most importantly, the asset should be on the 5488 port app assets folder, rather than creating an assets folder and put that in your project.
    E.G.

    1. connecting to http://example.com:5488
    2. in the GUI, click the "+" sign next to the assets folder
    3. select your asset to be uploaded.
    4. rename to what your project code point to ( like... {#asset myFileName.myExtension @encoding=dataURI} should name your asset name as: myFileName.myExtension)

    I dun know if this is the correct approach, but this should work fine.
    Maybe the assets document need to elaborate for more and the jsreport-client should write more about the assets too.
    Seems that the assets function are a newly item to the jsreport


Log in to reply
 

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