Node.js 如何将文件上传请求转发到nodejs中的另一个域?

Node.js 如何将文件上传请求转发到nodejs中的另一个域?,node.js,redirect,file-upload,request,form-data,Node.js,Redirect,File Upload,Request,Form Data,如何将上载请求转发到另一个域 用户界面将向发送上载请求 curl -X POST \ http://localhost:4000/uploadFile \ -H 'Accept: */*' \ -H 'Accept-Encoding: gzip, deflate' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Content-Length: 814459' \ -H 'Host:

如何将上载请求转发到另一个域

用户界面将向发送上载请求

curl -X POST \
  http://localhost:4000/uploadFile \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 814459' \
  -H 'Host: localhost:4000' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F attachment1=@/C:/Users/superman/Desktop/tester.pdf
需要附加2个附加标题并将请求转发给

curl -X POST \
  http://anotherdomain.com/anotherUploadFile \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'newheader1: headervalue1' \
  -H 'newheader2: headervalue2' \
  -H 'Content-Length: 814459' \
  -H 'Host: anotherdomain.com' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F attachment1=@/C:/Users/superman/Desktop/tester.pdf

首先,您将在第一个域中保存图像,然后启动一个新的post请求,该请求将获得保存的图像并转发到下一个域,如下所示。我正在使用“请求”npm包

 var options = { method: 'POST',
    url: server2 url,
    headers:
        { 
            'cache-control': 'no-cache',
            'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
    formData:
        { 
            filename:
                { value: fs.createReadStream(req.file.path),
                    options: { filename: req.file.path, contentType: null } } } };

request(options, function (error, response, body) {
    if (error) throw new Error(error);


});