fix: use streaming multipart upload for files > 2 GiB in writeBinary#310
fix: use streaming multipart upload for files > 2 GiB in writeBinary#310devin-ai-integration[bot] wants to merge 1 commit into
Conversation
When writeBinary receives a file path (string) for a file larger than the multipart threshold, it now uses fd-based streaming (openSync/ readSync) to read and upload chunks without loading the entire file into memory. This avoids the Node.js ERR_FS_FILE_TOO_LARGE error for files exceeding the 2 GiB Buffer size limit. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
LGTM
The implementation is correct and mirrors the existing blob-based uploadWithMultipart. The fd is properly guarded with a finally block, readSync with an absolute position argument is safe, Promise.all preserves insertion order so the sort is a harmless defensive step, and the abort-on-error path is wired correctly. The silent abort error swallow (line 532–534) matches common multipart conventions and is acceptable since the comment is explicit. No critical issues found.
Tag @mendral-app with feedback or questions. View session
Summary
Fixes
ERR_FS_FILE_TOO_LARGEerror when callingwriteBinarywith a file path pointing to a file larger than 2 GiB.Root cause: When
writeBinaryreceives a string (file path), it callsfs.readFileSync(content)which tries to load the entire file into a Node.js Buffer. Node.js Buffers have a hard 2 GiB size limit, causing the error for files like the user's 17 GiB file.Fix: Before calling
readFileSync, check the file size withfs.statSync. If the file exceeds the multipart threshold (5 MB), use a newuploadFileWithMultipartmethod that:fs.openSyncfs.readSync(bounded memory usage)This approach handles files of any size without hitting the Buffer limit.
Review & Testing Checklist for Human
writeBinary('/path/to/local/file')— should succeed withoutERR_FS_FILE_TOO_LARGEwriteBinary('/path/to/small/file')— should still use the regular single-request upload pathNotes
CompleteUploadasync on the server side to avoid CloudFront 504 timeouts during assemblyuploadWithMultipart(Blob-based) path is unchanged — this adds a paralleluploadFileWithMultipartpath specifically for local file paths that streams from diskLink to Devin session: https://app.devin.ai/sessions/25c0534a826d4e088768cf2c15fa1d53
Requested by: @Joffref
Note
Adds a streaming multipart upload path for file-path inputs exceeding
MULTIPART_THRESHOLD(5 MB), avoidingERR_FS_FILE_TOO_LARGEwhenreadFileSynchits the 2 GiB Buffer limit. UsesopenSync/readSyncwith an absolute offset to read fixed-size chunks sequentially, uploading them in parallel batches before completing the multipart upload.Written by Mendral for commit 19965a9.