fix(upload): sniff content type for application/octet-stream
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m51s
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:
@@ -397,7 +397,7 @@ func (s *UploadService) writeIncomingFilesToBox(ctx context.Context, box *Box, f
|
|||||||
storedName := "@each@" + fileID + strings.ToLower(filepath.Ext(incoming.Name()))
|
storedName := "@each@" + fileID + strings.ToLower(filepath.Ext(incoming.Name()))
|
||||||
objectKey := boxObjectKey(box.ID, storedName)
|
objectKey := boxObjectKey(box.ID, storedName)
|
||||||
contentType := incoming.ContentType()
|
contentType := incoming.ContentType()
|
||||||
if contentType == "" {
|
if contentType == "" || contentType == "application/octet-stream" {
|
||||||
buffer := make([]byte, 512)
|
buffer := make([]byte, 512)
|
||||||
n, _ := file.Read(buffer)
|
n, _ := file.Read(buffer)
|
||||||
contentType = http.DetectContentType(buffer[:n])
|
contentType = http.DetectContentType(buffer[:n])
|
||||||
|
|||||||
Reference in New Issue
Block a user