繁体   English   中英

从AWS Lambda(Nodejs Express with multer)上传到S3 Bucket,返回白色小框

[英]Uploading from AWS Lambda (Nodejs Express with multer) to S3 Bucket, returning white small box

我正在尝试从我的 lambda (nodejs express) 上传到 s3 存储桶。 但是每当我上传并在 S3 中查找我上传的文件时,它只显示一个白色的小框。 1个

我已经尝试将我的文件缓冲区转换为 base64,但它仍然无法正常工作。 我上传的文件只有在我使用本地 api(localhost) 上传时才会显示。

这是我的代码:

// multer middleware
const multer = require("multer");
const helpers = require("../helpers/image-upload-helper");
const storage =multer.memoryStorage();

let upload = multer({
   storage: storage,
   fileFilter: helpers.imageFilter,
   }).any();

//controller
 try {
    if(req.files){
      for (const file of req.files) {
        const ImageName = randomImageNameGenerator.randomImageName()
        const params = {
            Bucket: process.env.BUCKET_NAME,
            Key: ImageName,
            Body: file.buffer, 
            ContentType : file.mimetype,
        }
        const command = new PutObjectCommand(params)
        const myData =  await s3.send(command)
      }
    }


//log of my command 
PutObjectCommand {
  middlewareStack: {
    add: [Function: add],
    addRelativeTo: [Function: addRelativeTo],
    clone: [Function: clone],
    use: [Function: use],
    remove: [Function: remove],
    removeByTag: [Function: removeByTag],
    concat: [Function: concat],
    applyToStack: [Function: cloneTo],
    identify: [Function: identify],
    resolve: [Function: resolve]
  },
  input: {
    Bucket: 'orex-product-images',
    Key: 'b465138efab90aba02e5376ef247f536cfb1e7e32e34877bf21ab1bd655b3749',
    Body: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 f8 00 00 00 f5 08 06 00 00 00 bc c1 e7 15 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... 10640 more bytes>,
    ContentType: 'image/png'
  }
}

// log of myData 

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '6C1EM009PP420NRK',
    extendedRequestId: 'ZfGR4AR4mElYOSGes68YqEegptyO5PY5iPCvplP89wr1nqT4DZHwo0D0bl5qyZ7aAB0HaDaTAKU=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  ETag: '"96425366df243451e35a941524b2a019a6ad2b"',
  ServerSideEncryption: 'ABDS256',
  VersionId: 'rpgj.L5AwGNCcKVzatIY5zHf_SYVNWt0'
}

注意:我在我的云手表中没有看到任何错误

1白框外观示例在此处输入图像描述

对于那些像我一样遇到同样问题的人,这个答案为我解决了这个问题: Using Lambda to get image from S3 returns a white box in Python

对于那些使用无服务器的人,这也是相关的: Serverless I image upload to S3 broken after deploy, local worked only

暂无
暂无

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

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