问题描述
我正在尝试使用 next js 和 multer 上传文件。我使用与 aws s3 sdk 兼容的 digitalOcean 空间:
这是我的 s3 配置:
const spacesEndpoint = new aws.Endpoint("fra1.digitaloceanspaces.com");
const s3 = new aws.S3({
endpoint: spacesEndpoint,accessKeyId: process.env.SPACES_KEY_ID,secretAccessKey: process.env.SPACES_KEY_SECRET,});
这是multer配置:
const upload = multer({
storage: multerS3({
s3: s3,bucket: "pdf",acl: "public-read",key: function (req,file,cb) {
console.log("file",file);
try {
cb(null,file.originalname);
} catch (err) {
console.log(err);
}
},}),}).array("files");
我自己也调用 multer 来捕捉错误,正如 multer doc 所说,但我收到引用错误“err is not defined”
apiRoute.post((req,res) => {
console.log(req.body);
upload(req,res,function (err) {
if (err instanceof multer.MulterError) {
// A Multer error occurred when uploading.
} else if (err) {
// An unkNown error occurred when uploading.
}
// Everything went fine.
});
res.status(200).json({ data: "success" });
});
我也可以发布一个代码,其中我正在对 api 路由进行 axios 调用,但现在我只想查看来自服务器的 500 状态代码响应以外的任何信息
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)