我无法使用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