gpt4 book ai didi

amazon-web-services - 将 Puppeteer 截图重定向到 S3

转载 作者:行者123 更新时间:2023-12-04 00:13:51 25 4
gpt4 key购买 nike

我正在尝试做一些类似于 this person 的事情做了,但我很难弄清楚如何将 Puppeteer 截图的输出直接重定向到 S3,因为截图功能只有本地目录路径的参数。将图像存储在 Lambda 上是一种选择,但不是首选。

最佳答案

Passing a path to screenshot is optional.您可以省略路径并使用 Promise<[Buffer|String]>>它作为新 S3 对象的内容返回(在 await 之后)。假设你有 the AWS SDK并且已经设置了一个存储桶,您的配置将如下所示:

const AWS = require("aws-sdk");
const s3 = new AWS.S3();
const bucket = "your.bucket.name";
const key = "yourObjectKey";

然后,无论您准备好截取屏幕截图:
const screenshot = await page.screenshot();
const params = { Bucket: bucket, Key: key, Body: screenshot };
await s3.putObject(params).promise();

根据您打算使用它的目的,您可能需要添加 ContentType或其他相关的参数头。您可以在 the documentation 中查看列表.

关于amazon-web-services - 将 Puppeteer 截图重定向到 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51068493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com