已损坏的视频正在上传到S3

时间:2018-06-11 20:09:31

标签: node.js amazon-s3 aws-sdk multer aws-sdk-nodejs

这里我使用aws-sdk将视频从我的节点服务器上传到aws-s3存储桶。上传到aws存储桶的文件(例如大小为3MB)已损坏,因为上传的大小为20B。本地存储在我服务器上的视频打开正常,但是aws生成的链接也被破坏了,因为上传的内容非常少。server logs for file object and having 3.35MB AWS-S3 bucket with same file uploaded with size 45B



const storage = multer.diskStorage({
  destination: function (request, file, callback){
      callback(null, './videos');
  },
  filename: function(request, file, callback){
      console.log(file);
      callback(null, `${new Date().getTime()}_${file.originalname}`);
  }
});

const upload = multer({ storage: storage});

function uploadToS3(file, callback) {
  let s3bucket = new AWS.S3({
    accessKeyId: IAM_USER_KEY,
    secretAccessKey: IAM_USER_SECRET,
    Bucket: BUCKET_NAME
  });
  s3bucket.createBucket(function () {
	console.log(file)
      var params = {
        Bucket: BUCKET_NAME,
        Key: file.filename,
        Body: file.path,
	      ACL:'public-read',
	      ContentType: 'application/octet-stream',
      };
      s3bucket.upload(params, function (err, data) {
        if (err) {
          console.log('error in callback', err);
        }
        console.log('success', data);
        return callback(data);
      });
  });
}

app.post('/upload',  upload.single('element2'), (req, res, next)=>{
      const file = req.file;
      req.pause();
      uploadToS3(file, function(response){
        res.send(response)
      });
  });




0 个答案:

没有答案