我一直在尝试创建一个 AWS 节点 lambda 函数来从 S3 下载 PDF 文件,生成该文件第一页的缩略图,然后将该缩略图上传回 S3。由于我不是专家,所以我尝试从 AWS 提供的 Lambda 示例中启发自己调整图像大小,以及在 Node.js 中的 PDF 缩略图生成器的 SO 上找到的 Node.js,但未能使其工作。从 S3 下载有效,上传回 S3 有效,但缩略图生成失败。请参阅下面我的代码:
// Download the pdf from S3, create thumbnail, and upload to cache.
async.waterfall([
function download(next) {
// Download the pdf from S3 into a buffer.
s3.getObject({
Bucket: BUCKET,
Key: pdfkey
},
next);
},
function thumbnail(response, next) {
gm(response.Body[0]).size(function(err, size) {
// Transform the image buffer in memory.
this.resize(requestedwidth, requestedheight).toBuffer(format.toUpperCase(), function(err, buffer) {
if (err) { …Run Code Online (Sandbox Code Playgroud)