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

217
Vistas
How do I upload an MP3 held in state via Fetch to a Next.JS API Route?

I have a voice-recorder that records user-audio and stores it as state in a ReactJS component. When I pass the file to my API route it is recognised as a string and I don't seem to be able to upload it to AWS S3 correctly.

Here is the ReactJS button Handler:

  const [audioFile, setAudioFile] = useState(null)

  ...
  const submitVoiceMemo = async () => {
    console.log('this is the payload', audioFile)
    // the file is named 'audio.mp3'

    try {
      await fetch('/api/createVoiceMemo', {
        method: 'PUT',
        body: audioFile
      })
    } catch (error) {
      console.error(error)
    }
  }

However, when the file 'arrives' at the API Route it is a string and I don't know how to convert it back to an MP3:

module.exports = requireAuth(async (req, res) => {

    console.log(req.body) 
    // this prints 'characters' the to the console and is typeof string

I also can't seem to restructure req.body - if I try to console.log(req.body.audioFile) I get undefined.

How do I format the file so that I can upload it as an MP3 to AWS S3?

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