Next.js Discord

Discord Forum

Write file to disk within route.ts file

Unanswered
Cynipid gall wasp posted this in #help-forum
Open in Discord
Cynipid gall waspOP
Is it possible to stream a file to disk when submitted via a form (formData)?

Maybe I am missing something, but I see a limitation here. When you call await request.formData() it loads the file into memory.

What if my users upload a large file, and the server does not have enough memory to hold the file. I would like to write the file to disk so I can access it throughout the request lifecycle.

Imagine I am hosting my application on my own server, where I have 32GB of RAM, I upload a 50GB file, I need to store it on disk and not in memory. How can I do this?

1 Reply

Cynipid gall waspOP
if anyone ever runs into this thread, I have done the work, here it is: https://github.com/payloadcms/payload/tree/feat/next-poc/packages/next/src/next-fileupload