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

409
Vistas
How to send file from Nodejs to Flask Python?

Hope you are doing well. I'm trying to send pdfs file from Nodejs to Flask using Axios. I read files from a directory (in the form of buffer array) and add them into formData (an npm package) and send an Axios request.

 const existingFile = fs.readFileSync(path)                                
    console.log(existingFile)
    const formData = new nodeFormData()
    formData.append("file", existingFile)
    formData.append("fileName", documentData.docuName)
    try {
         const getFile = await axios.post("http://127.0.0.1:5000/pdf-slicer", formData,
                        {
                          headers: {
                                      ...formData.getHeaders()
                                   }
                           })
         console.log(getFile)} catch (e) {console.log(e, "getFileError")}

On flask side:

I'm trying to get data from the request.

    print(request.files)
    
    if (request.method == "POST"):
        file=request.form["file"]
        if file:
            print(file)

in request.file, I'm getting ImmutableMultiDict([])

but in request.form["file"], I'm getting data something like this:

request.form["file"] print example

how can I handle this type of file format or how can I convert this file format to python fileObject.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I solved this issue by updating my Nodejs code. We need to convert formData file into octet/stream format.

so I did minor change in my formData code :

before: formData.append("file", existingFile)

after: formData.append("file", fs.createReadStream(existingFile)

Note: fs.createReadStream only accepts string or uint8array without null bytes. we cannot pass the buffer array.

over 4 years ago · Santiago Trujillo Denunciar
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