payloadcms / payloadcms/payload
PDF missing from upload MIME fallback map
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
Payload's upload MIME fallback map does not include .pdf, so when file type detection from the buffer returns no result, a PDF filename falls back to text/plain.
That can cause valid PDF uploads to fail with:
File type text/plain (from extension pdf) is not allowed.
This was observed with Payload admin client uploads using @payloadcms/storage-vercel-blob.
Reproduction Context
A media collection allows PDFs explicitly:
upload: {
mimeTypes: ['image/*', 'application/pdf', 'video/*'],
}
Uploading a PDF through the Vercel Blob client upload flow submits metadata to /api/media after the direct Blob upload. In the server-side upload validation path, fileTypeFromBuffer(file.data) can return no detected type, then getFileTypeFallback('file.pdf') returns text/plain because pdf is not in extensionMap.
I checked payload@3.84.1, and dist/uploads/getFileTypeFallback.js currently maps common text/image-ish extensions but not pdf:
const extensionMap = {
css: 'text/css',
csv: 'text/csv',
htm: 'text/html',
html: 'text/html',
js: 'application/javascript',
json: 'application/json',
md: 'text/markdown',
svg: 'image/svg+xml',
xml: 'application/xml',
yml: 'application/x-yaml',
}
Expected Behavior
.pdf should fall back to application/pdf, so the existing application/pdf validation and PDF corruption check can run.
Suggested map addition:
pdf: 'application/pdf'
Environment
- Payload: confirmed in
3.80.0and3.84.1 - Storage adapter:
@payloadcms/storage-vercel-blob - Deployment target: Vercel
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dist/uploads/getFileTypeFallback.js and trace it to the corresponding source entry point. Reproduce the server-side upload validation path described for a PDF whose buffer type is undetected; done means the fallback resolves the PDF MIME type so the existing PDF validation can run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100