Skip to content

When using fetch for FormData upload files, lack of"\r\n" #3624

@JoeLeaf

Description

@JoeLeaf

Version

v20.14.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

(async () => {
  process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
  const axios = require("axios");
  const pic =
    "https://c2cpicdw.qpic.cn/download?appid=1407&fileid=Cgk3MDcxMDk4MzESFIdXk-Su5zb_v3YXR9IGh5-lYY7lGJmyUyD_CijP6aXtrb-IA1CAvaMB&rkey=CAQSMBcDFfD6aMnZO59Yn6VJT6zMyrgym718ZCG4J280hrOxtR2t-TLMZ5bE21i4-U0fOw&spec=0";
  const url = "https://web.qun.qq.com/cgi-bin/announce/upload_img";
  const cookies =
    "skey=MjHlWn1sIm; pskey=0MtTUBRnoPPWn4dKkwAN8g7jWjv7yz*yYdCOD*qNsCo_; uin=o3220300337";
  let data = new FormData();
  const picBlob = await (await fetch(pic)).blob();
  data.append("bkn", "1733032207");
  data.append("m", "0");
  data.append("source", "troopNotice");
  data.append("qid", "0");
  data.append("pic_up", picBlob, "a.jpg");
  console.log("-------------fetch-------------");
  let res = await fetch(url, {
    headers: {
      cookie: cookies,
    },
    method: "POST",
    body: data,
  });
  console.log(await res.json());
  console.log("-------------axios-------------");
  res = await axios.request({
    method: "post",
    url: "https://web.qun.qq.com/cgi-bin/announce/upload_img",
    headers: {
      cookie: cookies,
    },
    data: data,
  });
  console.log(res.data);
})();

The cookie here may have expired

Using axios can smoothly upload pictures, using fetch will prompt the picture error,By grabbing the package, I found that the loss at the end of the fetch was lost at the end of the upload"\r\n"

Missing "0d 0a 0d 0a" =>"\r\n\r\n"

fetch
axios

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

axios

Tail needs“0d0a”

What do you see instead?

fetch

Tail needs“0d0a”

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions