jsreport-aws-s3-storage plugin callback once upload done



  • Hello,

    I am trying to upload the pdf rendered files to an aws S3 using the jsreport-aws-s3-storage

    My setup could be described as following:

    1. mainTemplate is an empty template used to populate the list of reports to be generated and then
    2. within mainTemplate @afterRender, we call new templates using jsreport.render({ ...})

    we are using jsreport-aws-s3-storage plugin to store the generated output on aws server.

    I need to be able to detect once the pdf files has been uploaded successfully to aws.

    Thanks



  • The jsreport-aws-s3-storage is blob storage implementation used by reports extension.

    When you make a request like this:

       {
          "template": { "name" : "My template" },
          "data" : { ... },
          "options": {
              "reports": { "save": true }
          }
       }
    

    The output is persisted to the blob storage, in this case to AWS s3 object. This is done "synchronously" before the request finishes, so at the time you receive the response, the report is already in s3. The same applies when you call await jsreport.render.

    I probably just summarized what you already know, please try to elaborate more if this didn't help.



  • I will elaborate what I am trying to do and what I am expecting to get
    I have a list of templates that i need to generate. Using the jsreport-aws-s3-storage I was able to successfully upload the files to S3.

    1st Try

    for(var i in templates){
        var resp_pdf = await jsreport.render({ 
            template: { 
                name: templates[i].name
                recipe: 'chrome-pdf'
            }, 
            data: templates[i].data, 
            options: {
                   "reports": { "async": true, "blobName": templates[i].name},
                   "reportName": templates[i].name
             }                   
         })
    }
    

    However I need to find a way to make a callback call once all files has been generated and uploaded to S3.

    For that reason I tried first to put the above code at beforeRender of the main template and I was expecting that doing the callback from afterRender will take place only once all all files are on S3.

    await axios.get(CALLBACK_URL...
    

    But somehow, I was getting the response sooner, before all files has been sent to S3.


    2nd Try
    I tried to count the generated files and then fire the CALLBACK as following

    toRender = 100;
    
    for(var i in templates){
        var resp_pdf = await jsreport.render({ ... })
    
        if(resp_pdf) rendered++;
        if(rendered==toRender){ // CALLBACK }
    }
    

    Using this setup I noticed that the callback was fired as soon as all PDF files has been generated regardless if all of them has finished upload to s3 or not.

    I am open for suggestions, Is there a better way to fire callback once all files has been uploaded ?

    Thanks


Log in to reply
 

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