Replies: 3 comments 13 replies
-
You mean like this? https://nextjs.org/docs/app/building-your-application/routing/router-handlers#streaming |
Beta Was this translation helpful? Give feedback.
3 replies
-
Is there any way to do this with API routes in the pages router? It wants a |
Beta Was this translation helpful? Give feedback.
0 replies
-
export async function GET(req) {
const filePath = path.join(process.cwd(), 'public', req.nextUrl.searchParams.get('fileName') + '.html');
const res = new NextResponse(fs.createReadStream(filePath, { encoding: 'utf8' }));
res.headers.set('Content-Type', 'text/html');
return res;
} This is working very well. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I want to return a file in an API route. However, I don't know how to do that. Well.... this works:
but, I want to return the file in a streaming fashion. This means, I need to use something like the
ReadableStream
API. Not sure how to do this.Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions