- 注意:**在multer s3中得到下面的错误。这个错误指向NPM模块,我真的不明白这个模块的问题。我已经使用了upload. single以及upload. array方法来检查这个模块的工作。但是没有工作。
- 代码:**
const bodyParser = require('body-parser');
const cors = require('cors');
const aws = require('aws-sdk');
const multer = require('multer');
const multerS3 = require('multer-s3');
const http = require('http');
const app = express();
app.set('port', 3000);
app.use(
bodyParser.json({
limit: '50mb'
})
);
app.use(
bodyParser.urlencoded({
limit: '50mb',
extended: true
})
);
app.use(cors());
aws.config.update({
accessKeyId: '',
secretAccessKey: ''
});
s3 = new aws.S3();
const upload = multer({
storage: multerS3({
s3: s3,
bucket: '',
acl: 'public-read',
contentType: multerS3.AUTO_CONTENT_TYPE,
metadata: function (req, file, cb) {
cb(null, {
fieldName: file.fieldname
});
},
key: function (req, file, cb) {
let extArray = file.mimetype.split('/');
let ext = extArray[extArray.length - 1];
console.log(`ext ->> `, ext, ` file.fieldname ->> `, file.fieldname);
cb(null, "test/" + Date.now().toString() + '.' + ext);
},
/* limits: {
fileSize: 1024 * 1024 * 10
} */
})
});
(() => {
server = http.createServer(app).listen(app.get('port'), () => {
console.debug(`Server started ->> `);
app.get('/test', (req, res) => {Mul
res.send('Hello');
});
app.post('/media', upload.single('media'), (req, res) => {
console.log(`req.files ->> `, req.file);
res.send('Thanks for you waiting time');
});
});
})();
- 错误:**
ext ->> jpeg file.fieldname ->> media
TypeError: this.client.send is not a function
at Upload.__uploadUsingPut (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:52:25)
at Upload.__doConcurrentUpload (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:99:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
寻找解决方案与multer-s3。谢谢你提前。
5条答案
按热度按时间wbgh16ku1#
您是否检查过此问题?https://github.com/anacronw/multer-s3/issues/169
请检查你的aws-sdk,multer-s3版本是兼容的
46scxncf2#
只需按回车键:
tpxzln5u3#
multer-s3的3.x.x版本使用AWS JavaScript SDK v3。具体来说,它使用@aws-sdk/lib-storage中的Upload类,该类反过来调用模块化的S3 Client。请查看其github自述文件
kcrjzv8t4#
我也遇到了同样的问题。将multeridos 3降级到2x版本解决了这个问题!
Multer S3 2.x与AWS SDK 2.x兼容,Multer S3 3.x与AWS SDK 3.x兼容。
f0brbegy5#
对我来说,去掉这行字起了作用