-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to access request.body
as a stream in API routes
#7661
Comments
There will be an opt-out #7363 (comment). No idea as of what form of shape that will be. EDIT: Would like to add that to my preference, the opt-out wouldn't be configured the way AMP is configured, i.e. through a static config export. It should be possible for 3rd-party libraries to configure the opt-out themselves. For instance by having a property on the handler to signal to // third-party lib
export api () {
function api (req, res) {
req.pipe(myProxy).pipe(res);
}
api[Symbol.for('nextjs-opt-out')] = true;
return api;
}
// /api/handler.js
import { api } from 'third-party';
export default api(); |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
When handling API requests, we always try to parse the body depending on headers etc (see https://github.com/zeit/next.js/blob/canary/packages/next-server/server/api-utils.ts#L12-L39). However, in some cases you maybe don't want to save the whole body into memory but rather pipe it to some other stream to save memory. It'd be nice if we had access to the original
body
somewhere, or if we introduced an option to turn this off.I initially discovered the use for this when trying to parse
multipart/form-data
which most libraries expect to be a stream, but there might be other uses for this as well.The text was updated successfully, but these errors were encountered: