Async = true and output name



  • Hello,

    Using the API and setting options to:

    "options": { "reportName" : "myfile", "reports": { "async": true } }

    or

    "options": { "Content-Disposition": "attachment; filename=myfile.pdf", "reports": { "async": true } }

    doesn't set the filename. Is there something I'm doing wrong?



  • These options are used just to set the content-disposition header.
    It is not used in reports extension.

    I've submitted this as feature request.
    https://github.com/jsreport/jsreport/issues/458



  • I added this to reports.js and it will do what I need for the time being:

      	app.get('/reports/:id/attachment/:filename', function (req, res, next) {
    		serveReport(req, res).then(function (result) {
    			res.setHeader('Content-Disposition', 'attachment; filename="' + req.params.filename +'"')
    			result.stream.pipe(res)
    		}).catch(next)
    	})
    


  • So, I noticed https://github.com/jsreport/jsreport-reports/commit/0308ed26c9fd0e93a9aaa68401089b1f87a5f835 and that it is from last year. However, it doesn't seem to be in the most recent version of JSReport. Or if it is, it doesn't seem to work. Is it not supposed to be:

    "options":{"reportName": "SomeName.xlsx"}
    

    Is there still no way to set the report name? This is for when async is true, by the way.



  • The request should look like this

    { "options": { "reports": { "async": true, "blobName": "myfilename" } }
    


  • It comes back as content.xlsx when I do that.



  • This option specifies how the report should be persisted in the blob storage.
    What you mean with "it comes back"? Please be more specific.



  • I've figured it out. The url returned in the "Location" header is the content route. If I change it to attachment, then the file is returned with the name given in the "blobName" property. Otherwise, the file is named "Content.xlsx". Makes sense.



  • Actually, no. The filename indicated in the response header when requesting the attachment is the template name (that is, the name of the template in the jsreport studio). It isn't the name indicated when setting the "blobName" property in the request.

    For example, say i've got a template named RevenueReport. I make the request for the report, setting options:

    { "options": { "reports": { "async": true, "blobName": "LastQuarterRevenueReport" } }
    

    This creates a file called "LastQuarterRevenueReport.xlsx" on the server as expected, but when the file is requested with http://myjsereportserver/reports/8X2FZ2iqphQZp7uR/attachment, the file is named "RevenueReport.xlsx", not LastQuarterRevenueReport.xlsx. The response header doesn't say Content-Disposition: attachment; filename="LastQuarterRevenueReport.xlsx", it says Content-Disposition: attachment; filename="RevenueReport.xlsx".

    Shouldn't it say Content-Disposition: attachment; filename="LastQuarterRevenueReport.xlsx", as indicated in the "blobName" property?



  • hm, what if you send it like this?

    { 
      "options": { "reportName": "myfilename.xlsx", "reports": { "async": true, "blobName": "myfilename" } }
    }
    


  • That works! A mouthful, and maybe not super intuitive, but it works. Thanks Jan.



  • I see that the subsequent files of the same name are overwritten on the server. What if two different users create two different reports with the same name? If the first user doesn't download theirs in time, the may end up downloading the second users report instead. Is that right? That may have been something you've addressed before, but I'm not sure.



  • duh, nevermind. That's what the "blobName" field is for. Thanks Jan.


Log in to reply
 

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