NodeJS, Axios - post file from local server to another server

前端 未结 3 600
夕颜
夕颜 2020-12-15 21:23

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 ser

3条回答
  •  太阳男子
    2020-12-15 21:53

    This is what you really need:

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

提交回复
热议问题