[Solved] NodeJS, Axios – post file from local server to another server

Tri Nguyen Asks: NodeJS, Axios – post file from local server to another server
I have an API endpoint that lets the client post their csv to our server then post it to someone else server. I have done our server part which save uploaded file to our server, but I can’t get the other part done. I keep getting error { message: 'File not found', code: 400 } which may mean the file never reach the server. I’m using axios as an agent, does anyone know how to get this done? Thanks.

// file = uploaded file
const form_data = new FormData();
form_data.append("file", fs.createReadStream(file.path));
const request_config = {
    method: "post",
    url: url,
    headers: {
        "Authorization": "Bearer " + access_token,
        "Content-Type": "multipart/form-data"
    data: form_data
return axios(request_config);


As axios doc states as below and the API I’m trying to call requires a file

// data is the data to be sent as the request body // Only applicable for request methods ‘PUT’, ‘POST’, and ‘PATCH’ // When no transformRequest is set, must be of one of the following types: // – string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams // – Browser only: FormData, File, Blob // – Node only: Stream, Buffer

Is there any way to make axios send a file as a whole? Thanks.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.