I’m trying to stream data between two backends using Axios functions - downloadContent and uploadContent. The downloadContent function returns the data as a stream and the uploadContent function uses the stream to upload it.
However, when using the code below, the process memory usage is going up until it reaches the file size (5-10 GB+).
There is an issue with your approach. The problem is that when you use await with downloadContent, it buffers the entire response into memory before returning it. This is why your process memory usage increases.
To minimize the memory footprint and achieve streaming between two servers using Axios, you can use the response.data stream directly to pipe it to the uploadContent function. Here’s an updated version of your code:
In this updated code, responseType: "stream" is used to get the response as a stream. Then, the response.data stream is directly piped to the axios.post request, avoiding buffering the entire response in memory.
This approach will help minimize the memory footprint when streaming data between two servers using Axios.