简体   繁体   English

如何从Node中的Lambda函数将本地图像保存到S3

[英]How do I save a local image to S3 from my Lambda function in Node

I have a Node script that is attempting to do some image manipulation then save the results to S3. 我有一个Node脚本,它试图进行一些图像处理,然后将结果保存到S3。 The script seems to work, but when I run it the resulting image is just a blank file in s3. 该脚本似乎可以运行,但是当我运行它时,生成的图像只是s3中的空白文件。 I've tried using the result image, the source image etc, just to see if maybe see if it's the image ... I tried Base64 encoding and just passing the image file. 我尝试使用结果图像,源图像等,只是看是否可能是图像...我尝试了Base64编码并只是传递了图像文件。 Not really sure what the issue is. 不太确定是什么问题。

                var base_image_url = '/tmp/inputFile.jpg';
                var change_image_url = './images/frame.png';
                var output_file = '/tmp/outputFile.jpg'; 

               var params = {
                                Bucket: 'imagemagicimages',
                                Key: 'image_'+num+'.jpg',
                                ACL: "public-read",
                                ContentType: 'image/jpeg',
                                Body: change_image_url
                            }
                            s3.putObject(params, function (err, data) {
                                if (err)
                                {
                                    console.log(err, err.stack);
                                } // an error occurred
                                else
                                {
                                    callback("it");
                                    console.log(data);
                                }
                            });

It looks like this line… 看起来像这条线...

 Body: change_image_url

…is saving the string './images/frame.png' to a file. …正在将字符串'./images/frame.png'保存到文件中。 You need to send image data to S3 not a string. 您需要将图像数据发送到S3,而不是字符串。 You say you are doing image manipulation, but there's no code for that. 您说您正在执行图像处理,但是没有代码。 If you are manipulating and image, then you must have the image data in buffer somewhere. 如果要操作图像,则必须将图像数据放在缓冲区中的某个位置。 This is what you should be sending to S3. 这就是您应该发送给S3的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM