-
Notifications
You must be signed in to change notification settings - Fork 531
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
cannot read form data with readFormData
on vercel edge
#1721
Comments
This also occurs on Netlify: export default defineEventHandler(async event => {
if (event.method !== "POST") {
throw createError({statusCode:405, statusMessage: 'Method not allowed'});
}
let form: FormData;
try {
console.log('readFormData::enter');
form = await readFormData(event);
console.log('readFormData::exit');
} catch (cause) {
console.log('readFormData::error');
throw createError({
statusCode: 400,
statusMessage: 'Request has no FormData',
cause,
});
}
return form;
}); Output (via Logs > Functions on Netlify's admin panel)
The result is a 502 with message:
There are two major issues here:
With this severity of a crash, I'd honestly prefer the |
Using Reviewing the code for h3, specifically For example, |
This is a fixed version of async function readFormData_fixed(event: H3Event) : Promise<FormData> {
const request = new Request(getRequestURL(event), {
// @ts-ignore Undici option
duplex: 'half',
method: event.method,
headers: event.headers,
body: await readRawBody(event),
} as RequestInit);
return await request.formData();
} |
I ran into a similar problem with Netlify: unjs/h3#590 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This issue is already fixed with unjs/h3#616 (h3@1.10.1) I have implemented an end-to-end test which passes on edge platforms:
Note: Tests are against unmodified Nitro behavior. |
Moving from #1718 reported by @cosbgn
Minimal reproduction:
routes/index.ts:
(checking console, response never handles)
Workaround
You can use the older
readMultipartFormData
utility. It returns an array of form datas:https://nitro-ppspi2qf2-pi0.vercel.app/
The text was updated successfully, but these errors were encountered: