React native: how to get file size, mime type and extension?
In react-native-fs
you can use the stat
method (to get the file size)
import { stat } from 'react-native-fs';
...
const statResult = await stat('path/to/my/file.txt');
console.log('file size: ' + statResult.size);
With react-native-fetch-blob, you can get the file size with the code below:
RNFetchBlob.fs.stat(PATH_OF_THE_TARGET)
.then((stats) => {})
.catch((err) => {})
The response stats contains the following info:
{
// file name
filename : 'foo.png',
// folder of the file or the folder itself
path : '/path/to/the/file/without/file/name/',
// size, in bytes
size : 4901,
// `file` or `directory`
type : 'file',
// last modified timestamp
lastModified : 141323298
}
Source: https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#user-content-statpathstringpromisernfetchblobstat