fix(upload): sniff content type for application/octet-stream
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m51s

When an incoming file has an empty content type or is marked as
"application/octet-stream", attempt to detect the actual MIME type
by reading the first 512 bytes of the file. This improves content
type accuracy for generic binary uploads.
This commit is contained in:
2026-06-03 15:31:18 +03:00
parent 81f4ce5e36
commit 2eba04b9da

View File

@@ -397,7 +397,7 @@ func (s *UploadService) writeIncomingFilesToBox(ctx context.Context, box *Box, f
storedName := "@each@" + fileID + strings.ToLower(filepath.Ext(incoming.Name()))
objectKey := boxObjectKey(box.ID, storedName)
contentType := incoming.ContentType()
if contentType == "" {
if contentType == "" || contentType == "application/octet-stream" {
buffer := make([]byte, 512)
n, _ := file.Read(buffer)
contentType = http.DetectContentType(buffer[:n])