node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป


React Native - File Type

ReactNative: Detect the file type of a Buffer/Uint8Array by reading it from device (Android/iOS/Widnows) file system

This library is a React Native wrapper around sindresorhus/file-type node module.

The file type is detected by checking the magic number of the buffer.

sindresorhus/file-type: fileType(buffer) API, accepts a buffer of binary file data in order to determine it's meta data. Please find below usage for the same:

const readChunk = require('read-chunk');
const fileType = require('file-type');
const buffer = readChunk.sync('unicorn.png', 0, 4100);

//=> {ext: 'png', mime: 'image/png'}

We have created this library for the ease of use. Based on local storage path provided we internally use RNFS to read file and js-base64 to convert data into Uint8Array buffer which is expected by sindresorhus/file-type: fileType(buffer) API


Before we dive into on how to use this library. We would like to thank all the contributor of sindresorhus/file-type for providing such a awesome nice, cool library


npm install react-native-file-type

Internally we are using RNFS to read file. We have to link this library with our project:

react-native link react-native-fs


import fileType from 'react-native-file-type'

fileType('local-storage-path').then((type) => {
    //Ext: type.ext
    //MimeType: type.mime


Any type of contribution will be very much appreciated


Copyright @2017 Pranav Raj Singh Chauhan

The React Native File Type is provided under the MIT License.