在node环境使用axios发送文件

yarn add form-data

(async () => {
  const l = console.log;
  const axios = require("axios");
  const fs = require("fs-extra");
  var FormData = require("form-data");
  var form = new FormData();
  form.append("file", fs.createReadStream("C:\\Users\\Administrator\\Pictures\\a.jpg"));
  form.append("type", "avatar");

  let r = await axios({
    method: "post",
    url: "http://localhost:5000/upload",
    data: form,
    headers: form.getHeaders()
  }).then(v => v.data);

  l(r); // ok
})();

在node环境使用axios发送文件

上一篇:9、Collaborative Metric Learning Recommendation System: Application to Theatrical Movie Releases------CML推荐系统(电影院放映的应用)


下一篇:Jmeter入门13 jmeter发送application/octet-stream二进制流数据