-
Notifications
You must be signed in to change notification settings - Fork 0
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
See if Node 18 introducing a new FormData global could be of any use #1
Comments
This is weird, I swear to God I ran the code below on CF worker and it worked: let body = await request.formData();
let file = await body.get('file');
let fileData = await file.arrayBuffer();
Full code: const html = `
<FORM action="/upload_file" method="post">
<input type="file" name="file"/>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>`
async function ulpoadUrlAndReturnResponse(request, env) {
let body = await request.formData();
let file = await body.get('file');
console.log(typeof file)
let fileData = await file.arrayBuffer();
return new Response(typeof fileData, {
headers: {
"content-type": "text/plain",
},
});
}
export default {
async fetch(request, env) {
if (request.method === 'POST') {
return ulpoadUrlAndReturnResponse(request, env)
} else {
return new Response(html, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
}
},
}; |
@akoidan Do you have this flag on in both cases you describe? https://developers.cloudflare.com/workers/platform/compatibility-dates/#formdata-parsing-supports-file |
Thank you, I should have specified compatibilityDate, this flag is enabled by default. It's weird that w/o specified compatibilityDate, it's defaulted to some old piece of Node version. 👎 |
https://nodejs.org/en/blog/announcements/v18-release-announce/
Once the Workers runtime runs on Node 18, presumably CloudFlare will either switch to Node's
fetch
or alias it to their current implementation. Depending on which they do, this repository could become obsolete.The text was updated successfully, but these errors were encountered: