Home > Back-end >  How to download a csv file to firebase cloud function tmp with puppeteer without a direct url?
How to download a csv file to firebase cloud function tmp with puppeteer without a direct url?

Time:10-13

So I want to download a csv with puppeteer, which runs on a firebase cloud function.

Since I don't want it to be persistent, I want to store it in the cloud functions tmp folder. After some research I found that the best way to access this folders path is by calling os.tmpdir().

So this is 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);

But when I check this path again, there is no file in ${os.tmpdir()}` '/storageFolder'

At least when I do this:

fs.readdirSync(downloadPath).forEach(file => {
    console.log("Filename", file);
});

Nothing gets printed to the console.

I know there are multiple questions about this but every accepted answer is to download the file from the url but in my case there is no way to get the url.

So why is there no file in the specified folder? What am I doing wrong?

CodePudding user response:

can you store the file in cloud storage, cloud functions are meant to be stateless? Also, I can see you are using timeouts, which could be causing timing issues.

I wonder if you can use a solution where you don't need to use puppeteer :/

CodePudding user response:

I got it to work, at least locally.

I changed the downloadpath to

 const downloadPath = `${os.tmpdir()}\\downloads`;

It seems the way I did it was wrong.

  • Related