Piping stream from busboy to request post

前端 未结 3 1634
清歌不尽
清歌不尽 2021-02-05 14:18

I have multipart/form-data that I am posting to an express endpoint /data/upload, form markup below:

form(enctype=\"multipart/form-data         


        
3条回答
  •  情话喂你
    2021-02-05 14:42

    For the answer of Afanasii Kurakin

    request.post({
      url: server.baseURL + 'api/data',
      formData: {
        file: {
          value: fileStream,
          options: {
            knownLength: req.headers['content-length']
          }
        }
      }
    }, function (err, r, body) {
      // Do rendering stuff, handle callback
    })
    

    You should change from req.headers['content-length'] to the real file size, normally the content-length from header is bigger than the file size. I got pain because of the content-length and after using the file size, everything worked perfectly.

提交回复
热议问题