Skip to content
Advertisement

How to send file from React/Next.js client UI to Node server and next to Flask service

I want to send an Excel file from UI to Node JS, extract authorization token in NODЕ JS and then send to the Flask Server.

I don’t want to share my authorization token with the client UI, so I don’t want to send the file from there directly to Flask API. Also, I would like not to save the file on Node server-side, like if I send the file with FormData and parse it with formidable on Node server-side.

Something like: Reakt UI => Node.js(attach authorization token) => Flask(server)

My idea is to convert the file to array buffer, send it to Node server, and from there send it with the authorization token to Flask service.

My best approach to the moment is: In my client, I take the file with an input tag, create a buffer, and make a post request to API.

JavaScript

From API endpoint I make post request to Flask:

JavaScript

In Flask I receive the binries and want to create pandas dataframe:

JavaScript

I receive this traceback:

JavaScript

I am missing something essential or my approach isn’t correct. Will appreciate any help or guidance. Thanks!

Advertisement

Answer

May be this answer will help? Though it uses Form-Data lib.

Edit

Here example code for express and flask

JavaScript

and

JavaScript

working code here

Edit2

problem in your code is in express part. You are expecting to receive files from body, but files are not there

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement