-
I am trying to port an endpoint from Express that uses request module. The endpoint is used to upload a picture file from the browser. The Express endpoint serves as a pass-through proxy, sending the POST request into the downstream API where the picture is stored. I am not clear if I should use Undici.request, stream or pipeline for this, and how exactly. Something like: router.port("/upload", (req, res) => {
const undiciOptions = {
url: "https://api.acme.com/upload",
method: "post",
headers: req.headers
};
undiciOptions.headers.authorization = `bearer ${req.user.accessToken}`;
// NOW: which function from Undici should be used to stream the incoming multi-part form into the
// downstream API defined by undiciOptions?
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Any takers? |
Beta Was this translation helpful? Give feedback.
-
Actually I think I fixed it. It looks like if I provide Express request as the 'body' in body: Readable.toWeb(options.request), Another requirement is to provide a new dispatcher with |
Beta Was this translation helpful? Give feedback.
Actually I think I fixed it. It looks like if I provide Express request as the 'body' in
undiciOptions
, this works fine asstream
will treat this as a Readable:Another requirement is to provide a new dispatcher with
strictContentLength: false
passed into theAgent
constructor. With these two changes, I can stream multipart file uploads usingstream
into the ultimate destination.