react-nativevideo-upload

How to get video size in react native?


when uploading a video on, how to get its size.

I can set a limit to the duration but not the size.

I used this module

react-native-image-picker

this is the code used:

import ImagePicker from 'react-native-image-picker';

  ImagePicker.showImagePicker(options, response => {
  this.setState({ loading: false });

  if (response.didCancel) {
    console.log('User cancelled video picker');
  } else if (response.error) {
    console.log('ImagePicker Error: ', response.error);
  } else {
    let path = '';
    if (Platform.OS === 'android') {
      path = response.path;
    } else {
      path = response.uri;
    }
    const videoExtentionPos = path.lastIndexOf('.');
    const videoExtention = path.substring(videoExtentionPos + 1);

this.setState({
  fields: {
    ...fields,
    posts_video: {
      uri: response.uri,
      type: `video/${videoExtention}`,
      name: `video.${videoExtention}`
    }
  }
});

} });


Solution

  • There is not direct way to get it done. You will need to check the file size and show alert if it is not what you expect. You can get the file size with rn-fetch-blob package. You can use react-native-fs as well.