node转发formdata
阅读原文时间:2023年07月13日阅读:1

router.post('/keUpload', checkLogin, setAccessControlAllow, (req, res, next) => {
const busboy = new Busboy({
headers: req.headers,
})
const sendBuffer = (fileName, mimeType) => (fileBuffer) => {
const formData = {
uploadFile: {
value: fileBuffer,
options: {
filename: fileName,
contentType: mimeType
}
}
}
request.post({
url: 地址,
formData
}, function (err, response, body) {

}).pipe(res)
}
busboy.on('file', function (fieldName, fileStream, fileName, encoding, mimeType) {
fileStream.pipe(concat(sendBuffer(fileName, mimeType)))
})
req.pipe(busboy)
});