如何解决类型错误:元数据在上传到minio时应该是"对象"的类型



我想上传一个文件到minio,但是当我运行它时,我得到一个错误,像这样

TypeError: metaData should be of type "object"
at Client.fPutObject (/Users/berliana/Documents/nodejs-simple-file-upload/node_modules/minio/dist/main/minio.js:1210:15)
at Client.<anonymous> (/Users/berliana/Documents/nodejs-simple-file-upload/node_modules/minio/dist/main/helpers.js:74:51)
at /Users/berliana/Documents/nodejs-simple-file-upload/server.js:51:17
at Layer.handle [as handle_request] (/Users/berliana/Documents/nodejs-simple-file-upload/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/berliana/Documents/nodejs-simple-file-upload/node_modules/express/lib/router/route.js:137:13)
at Immediate._onImmediate (/Users/berliana/Documents/nodejs-simple-file-upload/node_modules/multer/lib/make-middleware.js:53:37)
at processImmediate (node:internal/timers:466:21)

这是我的代码

var minioClient = new minio.Client({
endPoint: 'play.min.io',
port: 9000,
useSSL: true,
accessKey: 'myaccesskey',
secretKey: 'mysecretkey'
});
app.post("/uploadfile", multer({dest: "./uploads/"}).single("files"), function(request, response) {
minioClient.fPutObject("berliana", request.file.originalname, request.file.path, "application/octet-stream", function(error, etag) {
if(error) {
return console.log(error);
}
response.send(request.file);
});
});

帮我解决这个问题

将元数据作为对象传递(如错误所示):

minioClient.fPutObject("berliana", request.file.originalname, request.file.path, {"Content-Type": "application/octet-stream"}, function(error, etag) {
if(error) {
return console.log(error);
}
response.send(request.file);
});

相关内容

  • 没有找到相关文章

最新更新