Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
Error 500 when trying to upload to AWS S3 with multer-s3

I am using express + multer-S3 to upload files to AWS S3. Using the following code, I get an internal server error 500 and I don't understand what I am doing wrong.

const aws = require("aws-sdk");
console.log("Require AWS");
const multer = require("multer");
const multerS3 = require("multer-s3");

const s3 = new aws.S3();

aws.config.update({
  secretAccessKey: process.env.S3_ACCESS_SECRET,
  accessKeyId: process.env.S3_ACCESS_KEY,
  region: "eu-west-3",
});

const fileFilter = (req, file, cb) => {
  if (file.mimetype === "image/jpeg" || file.mimetype === "image/png") {
    cb(null, true);
  } else {
    cb(new Error("Invalid file type, only JPEG and PNG is allowed!"), false);
  }
};

const upload = multer({
  fileFilter,
  storage: multerS3({
    acl: "public-read",
    s3: s3,
    bucket: "schubox",
    contentType: multerS3.AUTO_CONTENT_TYPE,
    metadata: function (req, file, cb) {
      console.log("Called when saving image  to AWS");
      cb(null, { fieldName: "TESTING_METADATA" });
    },
    key: function (req, file, cb) {
      console.log("FILE ==> " + JSON.stringify(file));
      cb(null, Date.now().toString());
    },
  }),
});

And in my route

router
  .route("/rayons")
  .get(auth, ctrlRayons.rayonsListe)
  .post(auth, **upload.single("fichier")**, ctrlRayons.rayonsCreerUn);

I get this error

Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1"

Error: connect EHOSTDOWN 169.254.169.254:80 - Local (192.168.1.10:56879) at internalConnect (net.js:934:16) at defaultTriggerAsyncIdScope (internal/async_hooks.js:452:18) at net.js:1022:9 at processTicksAndRejections (internal/process/task_queues.js:77:11)

What am I doing wrong? My AWS S3 account is ok, I have my Id and my secret ok, but nothing is written in my bucket. All the tutorials show the same procedure as the one I use.

Thanks again for your help.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!