serve dlna: fix MIME type if backend can't identify it

If the server returns the MIME type as application/octet-stream we
assume it doesn't really know what the MIME type. This patch tries
matching the MIME type from the file extension instead in this case.

This enables the use of servers (like OneDrive for Business) which
don't allow the setting of MIME types on upload and have a poor
selection of mime types.

Fixes #7259
This commit is contained in:
Nick Craig-Wood 2023-09-01 15:12:44 +01:00
parent b7ec75aab6
commit 85c29e3629
1 changed files with 5 additions and 0 deletions

View File

@ -60,6 +60,11 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
var mimeType string
if o, ok := fileInfo.DirEntry().(fs.Object); ok {
mimeType = fs.MimeType(context.TODO(), o)
// If backend doesn't know what the mime type is then
// try getting it from the file name
if mimeType == "application/octet-stream" {
mimeType = fs.MimeTypeFromName(fileInfo.Name())
}
} else {
mimeType = fs.MimeTypeFromName(fileInfo.Name())
}