Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda