1

I'm trying to upload files using next js and multer. I use digitalOcean spaces which is compatible with aws s3 sdk:

this is my s3 config:

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,
});

this is multer config:

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");

I'm also invoking multer by myself to catch the errors as the multer doc say but i get referece error "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" });
});

I can also post a code where i'm doing the axios call to the api route but right now i just want to see any more information than 500 status code response form the server

thsis the only error i'm getting: Error: Request failed with status code 500

aleksander frnczak
  • 399
  • 1
  • 2
  • 12

0 Answers0