Error: EACCES: permission denied, open 'image.jpg' code: 'EACCES'

The following code runs flawlessly when tested locally, but returns the following error when run during render cron job. This project is using puppeteer and I assumed there would be some limitations to using fs when deployed to render such as all files being deleted after instance spins down ect. However, I did not expect this. I only need the file to be stored for a couple seconds so I can then
use puppeteer to upload the file. What is the best way of doing this? Some sort of temp storage? I only need the file to be stored for a couple seconds so it can be uploaded.

Also, sorry if formatted this post wrong this is my first time posting! Please let me know if you need more code, context ect.

Thanks!

Error: EACCES: permission denied, open ‘image.jpg’

Code:

const imageUrl = ‘https://plus.unsplash.com/premium_photo-1669048776605-28ea2e52ae66?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D’;

const viewSource = await page.goto(imageUrl);
const buffer = await viewSource.buffer();
fs.writeFileSync('image.jpg', buffer);

await page.goto("https://medium.com/new-story");
await page.waitForSelector('h3', { timeout: 60000 });

await page.waitForSelector('[data-testid="editorAddButton"]');

// Click the button
await page.click('[data-testid="editorAddButton"]');

await delay("2000");

const [fileChooser] = await Promise.all([
    page.waitForFileChooser(),
    page.click('button[aria-label="Add an image"]')
]);
await fileChooser.accept(['image.jpg']);

Hi there,

Where are you trying to save the file to within the service? Most absolute paths (unless you have a disk) are going to be inaccessible – are you using a relative path from the service root to save the file?

It sounds like you are already aware of the ephemeral temporary storage, so I won’t go into that here. Just be aware that a persistent disk is available on Web/Private Services and Background Workers if/when needed.

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)