Sending streams as response
See original GitHub issueHi there,
Is it possible to send streams somehow? Roughly, I’m trying to do this:
@Get("/*")
public async processRequest(@Req() request, @Res() response) {
...
const readableStream = await myStorage.getBlobAsStream();
readableStream.pipe(response);
...
}
…and receive the error like this:
Application has thrown an uncaught exception and is terminated:
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at write_ (_http_outgoing.js:572:17)
at ServerResponse.write (_http_outgoing.js:567:10)
at RetriableReadableStream.ondata (_stream_readable.js:666:20)
at RetriableReadableStream.emit (events.js:182:13)
at RetriableReadableStream.Readable.read (_stream_readable.js:486:10)
at flow (_stream_readable.js:922:34)
at resume_ (_stream_readable.js:904:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
Could you please advise?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to stream to an HTTP response - Mario Kandut
Send a stream back to the client as a response to an HTTP request · 1. Initialize project and install dependencies · 2....
Read more >How do I stream response in express? - Stack Overflow
I've been trying to get a express app to send the response as stream. var Readable = require('stream'). Readable; var rs = Readable();...
Read more >Using readable streams - Web APIs | MDN
In our Simple stream pump example, we consume the custom readable stream by passing it into a Response constructor call, after which we...
Read more >Stream to an HTTP Response with Node.js - YouTube
In this tutorial we will use streams to efficiently send a large ... a large file into memory before sending it back as...
Read more >Implement HTTP Streaming with Node.js and Fetch API
Your API should use HTTP streaming to send its response. Your webapp should use the Fetch API to make the request so that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey all -
routing-controllers
does support returning streams directly from a controller method (via https://github.com/typestack/routing-controllers/pull/285), but I’ve found it a bit tricky at first when it comes to piping streams (i.e.readable.pipe(response)
).I’ve managed to get piping streams to work by using either of the two following methods:
1. Piping the readable to the response and returning a Promise
2. Piping the readable to a PassThrough stream and returning it
Note that with the Passthrough approach, I’ve encountered some issues with the content-type not being inferred automatically, so you may need to use
@ContentType
as well, depending on your use case.This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.