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

407
Views
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 answers
Answer question

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 Report
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!