Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda