Repository navigation
feat(storage): support custom upload content-type detection - #13
Merged
kamilmysliwiec merged 5 commits intoOct 8, 2026
Merged
kamilmysliwiec merged 5 commits into
kamilmysliwiec merged 5 commits into
Conversation
Let applications classify bounded prefixes for formats without magic signatures, preserving built-in signature detection as the default behavior. Closes nestjs#12
Allow custom detectors to use samples shorter than the built-in signature sniff length. Refs nestjs#12
Reject known signatures outside the allow-list before fallback detection. Refs nestjs#12
rafaself
marked this pull request as ready for review
October 6, 2026 21:47
Document the accepted one-byte lower bound for upload content samples. Refs nestjs#12
Match `contentTypes` and derive the key extension from the type's essence, so a detector can return `text/csv; charset=utf-8`. Extensions for detector types now come from the existing extension table instead of a CSV-only entry. Reject empty or non-string detector results with a clear error, read and copy the sample once, and document that the detector must settle promptly and that the exported `detectContentType()` is a no-op as the option.
1 of 5 tasks
Merged
3 tasks done
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.
PR Checklist
PR Type
What is the current behavior?
When
uploadToDisk()has acontentTypesallow-list, files without a recognized magic signatureare rejected. This prevents applications from allowing formats such as CSV.
Issue Number: #12
Scope
Addresses #12 by adding an optional async
detectContentType(bytes, file)fallback for unknownsignatures. The detector receives a configurable bounded prefix (4 KiB by default, up to 64 KiB).
Its result is checked against
contentTypesbefore any bytes are written and supplies the storedcontent type. CSV detection also gives default upload keys a
.csvextension.The API docs state that prefix detection does not validate the full file and that client-provided
MIME types and filenames are untrusted.
What is the new behavior?
Built-in signature detection remains the default and takes precedence. Applications can opt in to
classifying formats without signatures; an undefined result continues to be rejected by an
allow-list.
Does this PR introduce a breaking change?
Validation
npm run test:e2e: 887 passed, 17 skipped because MinIO is unavailable.npm run buildnpm run lintCloses #12