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

408
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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