To get the file size using response-native-fetch-blob, I used the following code
For this you need to install base-64
var base64 = require('base-64'); RNFetchBlob.fs.readFile(filePath, 'base64') .then((data) => { var decodedData = base64.decode(data); var bytes=decodedData.length; if(bytes < 1024) console.log(bytes + " Bytes"); else if(bytes < 1048576) console.log("KB:"+(bytes / 1024).toFixed(3) + " KB"); else if(bytes < 1073741824) console.log("MB:"+(bytes / 1048576).toFixed(2) + " MB"); else console.log((bytes / 1073741824).toFixed(3) + " GB"); })
Explanation:
- The above code decodes base64 data into a string such as atob ().
- Next string search length
- From this value I have to calculate the file size.
If the file is too large, use RNFetchBlob.fs.readStream instead of RNFetchBlob.fs.readFile
I get byte calculations from SO size conversion
The code may be too long to calculate the file size. If anyone finds the easiest way, advise me
source share