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

182
Vistas
How to save different filename to S3 using Multer-S3

I am trying to use Multer-S3 to upload a JSON file to S3. I can get it to upload if I set the filename on the backend to something like Date.now().toString() however when I try to set it to the name I want and pass from my frontend it fails. My goal is to be able to set the filename in a way that allows me to have S3 prefixes making it easier to process data later

Frontend

const userID = this.$store.getters.userID
      const accountCode = userID.account_code
      let formData = new FormData()
      if(this.upload){
        formData.append('import', this.upload)
        formData.append("fileName", `${accountCode}/${Date.now()}`)

        axios.post('/management/import', formData)
          .then(() => {
            this.successMessage = 'Successfully uploaded file'
          })
          .catch(error => {
            console.error(error)
            this.errorMessage = 'Error uploading file please try again'
          })
}

Backend

const upload = multer({
    storage: multerS3({
      s3: s3,
      bucket: config.AWS.IMPORT_BUCKET_NAME,
      metadata: function (req, file, cb) {
        cb(null, {fieldName: file.fieldname});
      },
      key: function (req, file, cb) {
        cb(null, Date.now().toString()) // Want this to be the formData.fileName seen in the frontend code
      }
    })
  })

router.post('/import', upload.single('import'), async(req, res) => {
    console.log(req.file)
    return res.json({success:true})
}
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