下一个 js,无法在 multer 中捕获错误

问题描述

我正在尝试使用 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 状态代码响应以外的任何信息

这是我得到的唯一错误错误:请求失败,状态码为 500

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...