Stream video uploads to disk instead of buffering in memory
req.formData() parsed the entire multipart body into RAM, so large uploads (1.6GB+) OOM-killed the server. Bridge the web Request body to a Node stream and parse it with formidable, which writes the file to disk as it arrives: - Temp dir is /uploads/tmp (same filesystem as the destination) so the post-parse move is an atomic rename, not a second multi-GB write - Mark the bridged request as chunked when a proxy strips content-length, otherwise formidable assumes an empty body - Track formidable temp files via fileBegin so aborted uploads get their partial files cleaned up - Remove the dead formidable branch gated on (req as any).req, which is always null in the App Router Also fix the nginx example in VPS_UPLOAD_CONFIG.md: client_max_body_size was 1024M, below the app's 2.5GB limit, and would 413 large uploads at the proxy before they reached the app. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,9 +63,10 @@ If running with a proxy (nginx/Apache), ensure:
|
||||
location /api/admin/upload {
|
||||
proxy_pass http://next-server;
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 300s; # 5 minutes for large uploads
|
||||
proxy_read_timeout 300s; # 5 minutes for large uploads
|
||||
client_max_body_size 1024M; # Adjust based on your max video size
|
||||
proxy_send_timeout 2700s; # 45 minutes, matches maxDuration in the route
|
||||
proxy_read_timeout 2700s; # 45 minutes, matches maxDuration in the route
|
||||
client_max_body_size 3G; # Must exceed the 2.5GB app-level limit
|
||||
proxy_request_buffering off; # Stream to the app instead of spooling to nginx disk
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user