fix: serve svg+xml as svg (#13277)
Based from https://github.com/payloadcms/payload/pull/13276 Fixes https://github.com/payloadcms/payload/issues/7624 If an uploaded image has `.svg` ext, and the mimeType is read as `application/xml` adjust the mimeType to `image/svg+xml`. --------- Co-authored-by: Philipp Schneider <47689073+philipp-tailor@users.noreply.github.com>
This commit is contained in:
@@ -93,9 +93,14 @@ export const getFileHandler: PayloadHandler = async (req) => {
|
||||
|
||||
const data = streamFile(filePath)
|
||||
const fileTypeResult = (await fileTypeFromFile(filePath)) || getFileTypeFallback(filePath)
|
||||
let mimeType = fileTypeResult.mime
|
||||
|
||||
if (filePath.endsWith('.svg') && fileTypeResult.mime === 'application/xml') {
|
||||
mimeType = 'image/svg+xml'
|
||||
}
|
||||
|
||||
let headers = new Headers()
|
||||
headers.set('Content-Type', fileTypeResult.mime)
|
||||
headers.set('Content-Type', mimeType)
|
||||
headers.set('Content-Length', stats.size + '')
|
||||
headers = collection.config.upload?.modifyResponseHeaders
|
||||
? collection.config.upload.modifyResponseHeaders({ headers }) || headers
|
||||
|
||||
Reference in New Issue
Block a user