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

195
Visualizações
How can i upload a file with custom name with multer-axios in nodejs

Im trying to upload a file with custom name with multer in nodejs

this is how i call from the frontend

const id = *some value*
Axios.post("http://localhost:3001/upload", formData, {headers: {'content-type': 'multipart/form-data'}})
        .then((response) => {
            window.location.reload()
        })

And this in the backend

const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, '../client/src/Images')
    },
    filename: (req, file, cb) => {
        cb(null, Math.trunc(Date.now()/1000).toString() + path.extname(file.originalname))
    }
})

const upload = multer({
    storage: storage,
    limits:{fieldSize: 1000000},
 })

app.post("/upload", upload.single('image'), (req, res) => {
    res.send("Image Uploaded")
})

Now the image is (correctly) saved with the name Date.now()/1000; but i want to saved with the name id that i have in the frontend, how can i pass that to multer?

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