错误:使用AWS Lambda上的gm降低图片质量时,stream会产生空缓冲区
我已阅读所有其他主题,并尝试了一些答案,但我似乎无法弄清楚为什么我得到这个错误。 我的代码在S3存储桶中获取上传的图片,降低质量并将其放入第二个存储桶中。 干净利落。 随着中小型图像一切正常,但如果我上传的东西超过2 MB(或多或less)我得到的错误标题。 我的Lambda函数有128MB和3分钟的超时时间; 这里是代码:
const gm = require('gm').subClass({imageMagick: true}); const AWS = require('aws-sdk'); const async = require('async'); const S3 = new AWS.S3(); exports.handler = (event, context, callback) => { var srcBucket = event.Records[0].s3.bucket.name; var srcKey = event.Records[0].s3.object.key; var dstBucket = "destinationbucket"; var dstKey = "resized-" + srcKey; // Infer the image type. var typeMatch = srcKey.match(/\.([^.]*)$/); if (!typeMatch) { callback("Could not determine the image type."); return; } var imageType = typeMatch[1].toLowerCase(); if (imageType != "jpg" && imageType != "png" && imageType != "jpeg") { callback('Unsupported image type: ${imageType}'); return; } async.waterfall([ function download(next) { S3.getObject({Bucket : srcBucket, Key : srcKey}, next); }, function transform(response, next) { var img_quality_reduced = gm(response.Body); img_quality_reduced.quality(75).toBuffer(function( error, buffer ) { if( error ) { console.log( error ); return; } next(null, response.ContentType, buffer); } ); }, function upload(contentType, data, next) { S3.putObject({Bucket: dstBucket, Key: dstKey, Body: data}, next); }, function ending(next) { console.log('got to ending'); context.done(); } ], function (err) { console.log(err); context.done(); }); };
任何想法为什么发生这种情况? 我已经加载了async,gm和graphicsmagick到Lambda(作为一个zip文件)。 所有通过npm下载
- 特拉维斯CI。 NetworkingError:Node.js和AWS S3存储桶之间的CERT_UNTRUSTED错误
- 在KeystoneJS中使用S3File进行image processing
- 使用NodeJS将file upload到Amazon S3
- 节点应用程序stream文件直接上传到amazon s3
- 用Node / Knox上传到S3:socket挂断
- 如何在客户端将可查看file upload到Amazon S3?
- 使用x-amz-tagging请求标头指定标签
- 我想在S3中存储用户的个人资料图像,并将其显示在客户端 – 将S3对象展示给移动客户端的最佳做法是什么?
- 从node.js中的JSON将s3桶策略转换为base64