0

我无法使用 multer-s3 上传大文件。它也没有给我任何错误。它只是不上传文件,甚至不进入回调并超时。有什么方法可以处理将大文件上传到 s3 Bucket?

我这样使用它:

var uploadSingle = upload.single('uploadFile');

router.post('/uploadVideo',function(req,res,next){  
    uploadSingle(req,res,function(err){
                // doesn't come here if the file is large
            if(err){
                //Error Response , Error while uploading Module PDF;
            }
            else{
                //handling file upload
               // success response
            }
    });
}
4

1 回答 1

0

我遇到了同样的问题,在研究了这个页面后,我发现我需要添加contentLength为参数之一。它的值是以字节为单位的长度。

const s3 = new AWS.S3({
    accessKeyId: process.env.S3_ACCESS_KEY_ID,
    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
});

var upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'myBucket',
    contentType: multerS3.AUTO_CONTENT_TYPE,
    contentLength: 500000000,
    metadata: function (req, file, cb) {
      cb(null, {fieldName: file.fieldname});
    },
    key: function (req, file, cb) {
      cb(null, file.originalname);
    }
  })
});

router.post('/uploadToS3', upload.array('photos', 30), function(req, res, next) {
  res.send({"message": 'Successfully uploaded ' + req.files.length + ' files!'});
})
于 2018-11-21T17:36:24.357 回答