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
})();
(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); })();

相关文章:

  • 2022-12-23
  • 2021-05-28
  • 2022-02-08
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-01-20
  • 2022-12-23
相关资源
相似解决方案