错误:意外字段 Amazon S3、Express、Multer、MulterS3



我收到此错误,我不知道为什么它会给我这个错误,我已经检查了与此相关的所有教程/类似问题,但没有任何效果。有人可以帮我指出正确的方向吗?

谢谢

错误:

意外字段

错误:
makeError 处出现意外字段 (C:\Users\Administrator\Desktop\express-cc-masterode_modules\multer\lib\make-error.js:12:13( at wrappedpedFileFilter (C:\Users\Administrator\Desktop\express-cc-masterode_modules\multer\index.js:40:19(

简介.js

var aws = require('aws-sdk')
var express = require('express');
var router = express.Router();
var multer = require('multer')
var multerS3 = require('multer-s3')

aws.config.loadFromPath('./config.json');
aws.config.update({
signatureVersion: 'v4'
});

var s3 = new aws.S3({});
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'raytestbucket123',
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
cb(null, Date.now()+file.originalname)
}
})
})
router.get('/profile', function(req, res){
res.render('profile', { title: 'Profile' });
});
router.post('/profile', upload.single('file'), function(req, res, next){
res.send(req.files);
console.log(req.files);
})
module.exports = router;

个人资料.hbs

{{> header }}
<body> 
<form action="/profile" method="POST" enctype="multipart/form-data">
File to upload to S3: 
<input name="file" type="file"> 
<br> 
<input type="submit" value="Upload File to S3"> 
</form> 
</body>
<div class="container">
<h2>Profile</h2>
</div>

我自己发现了问题。

而不是

res.send(req.files(; console.log(req.files(;

它应该是

res.send(req.file(; console.log(req.file(;

相关内容

  • 没有找到相关文章

最新更新