React Native - File Type is great but needs to be linked, and thus, won't work with a managed Expo project.
How can you read the file mime type when using Expo managed projects?
You can simply use the mime Javascript library to get the mime-type from the file name: https://www.npmjs.com/package/mime
import * as mime from 'mime';
const mimeType = mime.getType('my-doc.pdf') // => 'application/pdf'
If you are using the DocumentPicker to get the file, you can obtain the file name from the result directly:
const result = await DocumentPicker.getDocumentAsync();
if (result.type === 'cancel') {
return;
}
const fileName = result.name;
const mimeType = mime.getType(fileName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With