Currently, I am trying to use puppeteer to download a CSV file within a Firebase cloud function. To ensure that the file is not persistent, my plan is to store it in the cloud functions tmp folder. Through some investigation, I discovered that the most efficient way to access this folder's path is by utilizing os.tmpdir()
.
Here is the code snippet for my current function:
const downloadPath = `${os.tmpdir()}` + '/storageFolder';
await page._client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: downloadPath,
});
await page.waitForTimeout(500);
await page.$eval('mybutton', (mybutton) => mybutton.click());
await page.waitForTimeout(1000);
Despite implementing this code, when I check the specified path again, there is no file present in
${os.tmpdir()}` + '/storageFolder'
Even when I attempt to do so using the following code snippet:
fs.readdirSync(downloadPath).forEach(file => {
console.log("Filename", file);
});
No files are being printed to the console. Although there are various questions on this topic, the majority of accepted solutions involve downloading the file directly from the URL. In my situation, accessing the URL is not feasible.
Why is there no file appearing in the designated folder? What could be the potential error in my setup?