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

181
Views
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
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!