Skip to content

Commit 0c153b0

Browse files
committed
fix: support loading .nii.gz files from local file system
Browsers provide application/gzip MIME type for .nii.gz files. The updateFileMimeType handler now checks if the browser-provided type is in our supported list before skipping. If the type is unsupported (like application/gzip), it continues to check the filename extension to correctly identify compound extensions like .nii.gz, .gipl.gz, etc.
1 parent c736369 commit 0c153b0

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/io/import/processors/importSingleFile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const importSingleFile: ImportHandler = async (dataSource) => {
4343
return asLoadableResult(dataID, dataSource, 'model');
4444
}
4545

46-
throw new Error('Data reader did not produce a valid dataset');
46+
throw new Error(
47+
`Failed to import "${dataSource.file.name}". The file may be corrupted or in an unsupported format variant.`
48+
);
4749
};
4850

4951
export default importSingleFile;

src/io/import/processors/updateFileMimeType.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { Skip } from '@/src/utils/evaluateChain';
22
import { getFileMimeType } from '@/src/io';
33
import { ImportHandler, asIntermediateResult } from '@/src/io/import/common';
4+
import { MIME_TYPES } from '@/src/io/mimeTypes';
45

56
/**
67
* Transforms a file data source to have a mime type
78
* @param dataSource
89
*/
910
const updateFileMimeType: ImportHandler = async (dataSource) => {
10-
if (dataSource.type !== 'file' || dataSource.fileType !== '') return Skip;
11+
if (dataSource.type !== 'file') return Skip;
12+
13+
const knownType =
14+
dataSource.fileType !== '' && MIME_TYPES.has(dataSource.fileType);
15+
if (knownType) {
16+
return Skip;
17+
}
1118

1219
const mime = await getFileMimeType(dataSource.file);
20+
1321
if (!mime) {
14-
throw new Error('File is unsupported');
22+
throw new Error(
23+
`Unrecognized file type for "${dataSource.file.name}". This file format is not supported.`
24+
);
1525
}
1626

1727
return asIntermediateResult([

0 commit comments

Comments
 (0)