Procházet zdrojové kódy

utils: Add fallback to getFileType (#1022)

If we can't determine the file type, use the generic
'application/octet-stream' type. This way `file.type` will always be
defined and uploaders don't have to worry about it being `null` or
whatever.
Renée Kooi před 6 roky
rodič
revize
f958638455

+ 2 - 2
packages/@uppy/utils/src/getFileType.js

@@ -19,6 +19,6 @@ module.exports = function getFileType (file) {
     return mimeTypes[fileExtension]
     return mimeTypes[fileExtension]
   }
   }
 
 
-  // if all fails, well, return empty
-  return null
+  // if all fails, fall back to a generic byte stream type
+  return 'application/octet-stream'
 }
 }

+ 1 - 1
packages/@uppy/utils/src/getFileType.test.js

@@ -42,6 +42,6 @@ describe('getFileType', () => {
       name: 'foobar',
       name: 'foobar',
       data: 'sdfsfhfh329fhwihs'
       data: 'sdfsfhfh329fhwihs'
     }
     }
-    expect(getFileType(file)).toEqual(null)
+    expect(getFileType(file)).toEqual('application/octet-stream')
   })
   })
 })
 })