remix: [Bug]: Larger files are not readable via UploadHandler
Which Remix packages are impacted?
-
remix(Remix core) -
create-remix -
@remix-run/architect -
@remix-run/cloudflare-workers -
@remix-run/dev -
@remix-run/express -
@remix-run/netlify -
@remix-run/node -
@remix-run/react -
@remix-run/serve -
@remix-run/server-runtime -
@remix-run/vercel
What version of Remix are you using?
1.1.1
What version of Node are you using? Minimum supported version is 14.
16.1.0
Steps to Reproduce
Upload a file using the Form component.
Add a custom UploadHandler:
export const action: ActionFunction = async ({ request }) => {
const handler: UploadHandler = async ({ name, stream }) => {
if (name === 'foo') {
const buff = await new Promise<Buffer>(async (resolve, reject) => {
const chunks: any = [];
stream.on("readable", () => {
let chunk;
while (null !== (chunk = stream.read())) {
console.log('chunk...', chunk);
chunks.push(chunk);
}
});
stream.on("end", () => {
console.log('end');
return resolve(Buffer.concat(chunks));
});
});
}
}
const form = await unstable_parseMultipartFormData(request, handler);
// ..
};
Expected Behavior
The Readable stream should trigger the end event once consumed.
Actual Behavior
For small files (e.g. 10kb) the stream is handled correctly, and the end event is called. However, for larger files (90kb fails), a single chunk is logged, but then nothing else happens. The end event is never called.
Am I doing something wrong? I just cannot figure this out. The handling of the stream example is even taken from the nodejs docs.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 21
- Comments: 20 (2 by maintainers)
Commits related to this issue
- patch-package based on https://github.com/remix-run/remix/issues/1164 — committed to Alazoral/json-parse-example-remix by Alazoral 2 years ago
- [BUGFIX] Remove request.clone() in action to make upload "big" files work Linked to issue #1164 It seems that a few people struggle to setup an upload file action It seems that fixing that line se... — committed to arnaudambro/remix by arnaudambro 2 years ago
- [BUGFIX] Remove request.clone() in action to make upload "big" files work Linked to issue #1164 It seems that a few people (including myself) struggle to setup an upload file action It seems that ... — committed to arnaudambro/remix by arnaudambro 2 years ago
- [BUGFIX] Remove request.clone() in action to make upload "big" files work Linked to issue #1164 It seems that a few people (including myself) struggle to setup an upload file action It seems that ... — committed to arnaudambro/remix by arnaudambro 2 years ago
For now, make the single line change required in node_modules/@remix-run/server-runtime/server.js, then run
npx patch-package @remix-run/server-runtimeThis will create a patch file inpatches/xxxAddnpx patch-packageas a post install script and it will re-apply the change whenever younpm installI made a mistake in the last comment, it is data.js not server.js @anges244 @jacob-ebey - I just hacked the file for the purpose of the video
line 37 in For now, make the single line change required in node_modules/@remix-run/server-runtime/data.js,
https://discord.com/channels/770287896669978684/921148525948067850/923329464719536239
I’ll add the comment here because it’s more relevant to this issue:
I’m having issues uploading larger images. After searching on the Discord server, I found this comment from cmwoodall:
Hey @timonweb if you look at the answers above, you can use patch-package to apply the fix in your other environments
https://github.com/remix-run/remix/issues/1164#issuecomment-1001735640