Help to check if image exists



  • Hello!
    I have a problem and I can't find the solution, so here's the problem:

    I have an image and the image is in a separate folder from the main project, for example:
    0_1693489646258_upload-e6f9b14d-ca5d-4a33-a8fe-8cec801a4cf0

    The number 1 is my folder with imagem and, the number 2, is my folder with main project.

    The situation is:

    • My "script file" contains the following code below.
      0_1693489790495_upload-0bec9511-32c0-4f08-80e5-741248f01b0d
    • My "dSet file" contains the following code below.
      0_1693490223927_upload-e4fdbde4-974e-4a0f-bc65-28d70b934dc9
    • My "mytemplate file" contains the following code below.
      0_1693490492065_upload-4ea53ecb-2de1-4376-8dbf-d6787b1b4182

    First, I would need that in my "script file", I could pass the full path, as shown in the image

    Second, when the logo.png file doesn't exist in the folder, it doesn't show anything (which is what I would like) or else it shows this error (Asset ../../folder/logo.png not found in the store and also not on the disk: Unable to find or read file /folder/logo.png), however, when I add the logo back, it cannot find the logo and is blank, as if it does not exist.

    Thanks for the help.



  • Does this help? Note we may change this API in the future, but so far it should work.

    const resolvedCurrentDirectoryPath = await jsreport.currentDirectoryPath()
    const searchResult  = await jsreport.folders.resolveEntityFromPath(path, 'assets', { currentPath: resolvedCurrentDirectoryPath })
    
    if (searchResult == null) {
        // entity doesn't exist on patyh
    } else {
       // exist
    }
    

Log in to reply
 

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