Skip to content

Commit bc86bc2

Browse files
committed
Enhance NIfTI file handling by adding support for multiple NIfTI MIME types in the upload process
1 parent 801182c commit bc86bc2

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

datamint/apihandler/root_api_handler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from medimgkit import dicom_utils, standardize_mimetype
1111
from medimgkit.io_utils import is_io_object
1212
from medimgkit.format_detection import guess_typez, guess_extension, DEFAULT_MIME_TYPE
13-
from medimgkit.nifti_utils import DEFAULT_NIFTI_MIME
13+
from medimgkit.nifti_utils import DEFAULT_NIFTI_MIME, NIFTI_MIMES
1414
import pydicom
1515
from pathlib import Path
1616
from datetime import date
@@ -89,11 +89,15 @@ async def _upload_single_resource_async(self,
8989
is_a_dicom_file = None
9090
if mimetype is None:
9191
mimetype_list, ext = guess_typez(file_path, use_magic=True)
92-
mimetype = mimetype_list[-1]
93-
if mimetype == 'application/gzip':
94-
# Special case for gzipped NIfTI files
92+
for mime in mimetype_list:
93+
if mime in NIFTI_MIMES:
94+
mimetype = DEFAULT_NIFTI_MIME
95+
break
96+
else:
9597
if ext == '.nii.gz' or name.lower().endswith('nii.gz'):
9698
mimetype = DEFAULT_NIFTI_MIME
99+
else:
100+
mimetype = mimetype_list[-1] if mimetype_list else DEFAULT_MIME_TYPE
97101

98102
mimetype = standardize_mimetype(mimetype)
99103
filename = os.path.basename(name)

0 commit comments

Comments
 (0)