建议将临时文件放在一个单独的目录中,而不是放在根目录或tmp目录。例如,可以创建一个名为"temp"的目录,并将文件放在其中:

const tempDir = path.join(__dirname, 'temp'); if (!fs.existsSync(tempDir)) { fs.mkdirSync(tempDir); }

const fileinput = ${Date.now()}.mmd; fs.writeFileSync(path.join(tempDir, fileinput), input);

const filehtml = ${Date.now()}.html; fs.writeFileSync(path.join(tempDir, filehtml), renderedHtml);

const output = ${Date.now()}.png; await page.screenshot({ path: path.join(tempDir, output), fullPage: true, type: 'png' });

const imageStream = fs.createReadStream(path.join(tempDir, output)); response.setHeader('content-type', contentType); response.send(imageStream)

不要把代码里面临时文件放在tmp目录全都放在根目录const fs = requirefs;const path = requirepath;const puppeteer = requirepuppeteer;const contentType = imagepng;const launchBrowser = async = const browser = await puppeteerl

原文地址: https://www.cveoy.top/t/topic/gKVo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录