我无法使用 multer-s3 将大文件上传到 aws。我正在使用以下代码:
const upload = multer({
storage: multerS3({
s3,
bucket: 'welive-inc',
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, {fieldName: 'TESTING_META_DATA!'});
},
key: function (req, file, cb) {
cb(null, Date.now().toString() + randtoken.uid(16))
}
})
})
const singleUpload = upload.single('file');
router.post('/image-upload', (req, res) =>{
singleUpload(req, res, function(err) {
if (err) {
console.log(err)
return res.status(422).send({errors: [{title: 'File Upload Error', detail: err.message}] });
}
return res.json({'imageUrl': req.file.location});
});
});
此代码适用于小文件(图像或非常小的视频),但当涉及到相对较大的文件时,它不起作用。并且 console.log(err) 返回此错误:
{ Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:66:16)
message: 'write EPIPE',
errno: 'EPIPE',
code: 'NetworkingError',
syscall: 'write',
region: 'eu-west-3',
hostname: 'welive-inc.s3.eu-west-3.amazonaws.com',
retryable: true,
time: 2019-06-17T21:15:46.958Z,
statusCode: 400,
storageErrors: [] }
前端甚至不等待响应并在几分钟后返回此错误
net::ERR_EMPTY_RESPONSE