节点抓取是否支持请求转发?

6psbrbz9  于 2022-10-01  发布在  其他
关注(0)|答案(0)|浏览(85)

我正在尝试将此代码翻译为与node-fetch一起使用,但我有点纠结于弄清楚node-fetch如何转发整个req比特,因为它包含了我想要上传的文件。

async function handler(req, res) {
  let uploadPhotoAddress = baseURL + "/upload";
  if (req.method == "POST") {
    const { data } = await axios.post(uploadPhotoAddress, req, {
      responseType: "stream",
      headers: {
        "Content-Type": req.headers["content-type"], // which is multipart/form-data with boundary included
        apikey,
      },
    });
    data.pipe(res);
  } else {
    return res.status(405).json({ message: "Method Not Allowed" });
  }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题