Wednesday, March 8, 2017

Blob created on client side doesn't get updated with new data

I am creating an angularjs/laravel application and I needed to implement a feature to export certain data to PDF. The PDF gets generated on the backend using laravel dompdf and is sent to angular as a result of a GET request. I am also using Angular File Saver to handle saving the file on the success callback of the request. So far the code looks like this on angular

function (response) {
     var data = new Blob([response.data], { type: 'application/pdf' });
     console.log(data);
     FileSaver.saveAs(data, 'balance.pdf');
}

This works just fine. The PDF gets generated and saved correctly. The problem is that when I update the data (any CRUD operation - which also are performed correctly) and afterwards I call the export function to save the PDF again it gets saved with the old data. The console.log(data) line is showing me that the Blob is created always with the same size (I don't know why because I'm using the new keyword so I'm creating a new object in memory, unless I'm mistaken). In order to get the PDF with the updated data I would have to manually refresh the browser, which kind of defeats the purpose of a SPA and also leaves the user confused. If anyone can provide any hint as to why this happens I would appreciate it. Thanks in advance



via hrivera

Advertisement