I'm facing a challenge with my Vue app where I need to compress a group of PDF files in a folder using JSZip. While testing with just one file, the zip downloads successfully but when I try to open the PDF file inside it, the content appears blank. I am fetching the buffer bytes from the backend using axios and that part seems fine. However, I can't figure out why the content is blank after compression with JSZip. I am using file-saver for downloading the compressed file.
Here is an excerpt of my script:
const user = this.getSelectedUser(values.employee);
const url = `some-url`;
await ReportRepository.getReport(url).then(({ data }) => {
console.log(Buffer.from(data).toString('base64'));
zip.file('timesheet.pdf', Buffer.from(data).toString('base64'), { binary: true });
zip.generateAsync({ type: 'blob' }).then((content) => {
saveAs(content, 'timesheet.zip');
});
}).catch((er) => {
console.log(er);
});
I'm unsure of where I went wrong and how to resolve the issue. Are there any changes or steps I could take to address this problem?