adverse-sapphire
adverse-sapphire•2y ago

download the file and save as specified filename

I am building a automation tool using puppeteer, and I am going to download the file with the give file name and save it as specified file names. For example, I want to download the pdf file https://www.okcc.online/document.php?s=2y08wAM0TAlm2JACdE1Odb9keuvnLvSujwEnJ3bFigVrINRJoRV8HKR2&d=DOCCD-1910221606-MTG&t=rod and save as 1910221606.pdf I have built this function as myself but it only saves as original file name like "Unofficial Document.pdf" const localFilePath = ./${instrumentNumber}.pdf; const pdfURL = https://www.okcc.online${iframeSrc}; await page.evaluate( (link, localFilePath) => { const a = document.createElement("a"); a.href = link; a.download = localFilePath; a.style.display = "none"; document.body.appendChild(a); a.click(); document.body.removeChild(a); }, pdfURL, localFilePath );
2 Replies
Lukas Krivka
Lukas Krivka•2y ago
That's an interesting way to download a file! 🙂 I would probably just programmatically rename the file after being downloaded to your system
adverse-sapphire
adverse-sapphireOP•2y ago
i see thank you

Did you find this page helpful?