React-native-camera: How to get the bytes size of captured photo ?

Created on 1 Sep 2017  路  1Comment  路  Source: react-native-camera/react-native-camera

Hi. At first, thank you very much for this lib, it is really awesome!
But I got some trouble when tried to get the captured photo size in bytes.
In readme file is only guide to get the video size on iOS .
Is there any solutions for android photo?

Most helpful comment

Well I have found the solution.
You just need to install react-native mime-types, base64 and RNFetchBlob and watch my code:

let base64 = require('base-64');
let mime = require('mime-types')

        const options = {};
        if(this.refs.cam) {
            this.refs.cam.capture({ metadata: options })
            .then((data) => {       
                RNFetchBlob.fs.readFile(data.path, 'base64').then(r => {
                    var decodedData = base64.decode(r);
                    data.mime = mime.lookup(data.path);
                    data.size = decodedData.length;
                    this.share([data])
                    this.setState({ camera: false })
                })              
            })
            .catch(err => console.error(err));
        }

>All comments

Well I have found the solution.
You just need to install react-native mime-types, base64 and RNFetchBlob and watch my code:

let base64 = require('base-64');
let mime = require('mime-types')

        const options = {};
        if(this.refs.cam) {
            this.refs.cam.capture({ metadata: options })
            .then((data) => {       
                RNFetchBlob.fs.readFile(data.path, 'base64').then(r => {
                    var decodedData = base64.decode(r);
                    data.mime = mime.lookup(data.path);
                    data.size = decodedData.length;
                    this.share([data])
                    this.setState({ camera: false })
                })              
            })
            .catch(err => console.error(err));
        }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

ksokhan picture ksokhan  路  3Comments

Fernando-Parise picture Fernando-Parise  路  3Comments

WarrenBuffering picture WarrenBuffering  路  3Comments

aiibe picture aiibe  路  3Comments