Repository navigation
fix: use buffer byteLength for external file size (#18382) - #18390
Open
PINYOPATTANAWASANPORN wants to merge 1 commit into
Open
PINYOPATTANAWASANPORN wants to merge 1 commit into
PINYOPATTANAWASANPORN wants to merge 1 commit into
Conversation
…s#18382) When downloading an external file to buffer in downloadFileToBuffer, size was previously read from the response Content-Length header with fallback to 0. When Content-Length is omitted (chunked transfer) or represents compressed transport size, filesize was either 0 or inaccurate. Use the actual in-memory buffer byteLength (data.byteLength). Fixes payloadcms#18382
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
downloadFileToBufferinpackages/payload/src/uploads/downloadFileToBuffer.tsto assignsize: data.byteLengthdirectly from the downloaded buffer array buffer rather thanNumber(response.headers.get('content-length')) || 0.packages/payload/src/uploads/downloadFileToBuffer.spec.tsensuring accurate file size resolution even when the upstream server omitscontent-length(e.g. chunked transfer or compressed storage responses).Root Cause / Technical Context
When downloading an external file to buffer (e.g., creating from URL via Paste URL, duplicating, or re-fetching from cloud storage adapters like
@payloadcms/storage-vercel-blob),downloadFileToBufferrelied onNumber(response.headers.get('content-length')) || 0.In cases where:
Transfer-Encoding: chunked),Content-Lengthis omitted, causingfilesizeto be recorded as0.Content-Lengthrepresents compressed transport bytes rather than the decompressed body size.Because
response.arrayBuffer()is already completely buffered into memory asdata, usingdata.byteLengthprovides the exact byte size of the decoded payload.Verification & Testing
packages/payload/src/uploads/downloadFileToBuffer.spec.tsverifying file size calculation withoutcontent-lengthheader.downloadFileToBuffer.ts+ unit test).Fixes #18382