关于reactnative安卓端开发视频压缩上传怎么做呀



  • 现在是视频可以上传, 但是内存过大的就不行了,上传不了;用的控件是react-native-image-picker。

    代码: //拍视频
    selectVideoTapped() {
    const options = {
    title: '',
    takePhotoButtonTitle: '拍视频',
    chooseFromLibraryButtonTitle: '从视频中选择',
    cancelButtonTitle: '取消',
    mediaType: 'video',
    videoQuality: 'medium'
    };

        ImagePicker.showImagePicker(options, (response) => {
            console.log('Response = ', response);
    
            if (response.didCancel) {
                console.log('User cancelled video picker');
            } else if (response.error) {
                console.log('ImagePicker Error: ', response.error);
            } else if (response.customButton) {
                console.log('User tapped custom button: ', response.customButton);
            } else {
                this.setState({
                    videoSource: response.uri
                });
    
                let data = new FormData();
                data.append('file', {
                    uri: response.uri,
                    name: 'image.mov',
                    type: 'video/quicktime'
                });
    
                fetch('http://xxxxxxxxxxxxxxxxxxxx', {
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'multipart/form-data;'
                    },
                    method: 'post',
                    body: data
                }).then((response) => response.text()).then((responseText) => {
                    console.log(responseText);
                    var responseModel = JSON.parse(responseText);
                    // var response
                    if (responseModel.code == 0) {
                        this.state.contentList.push({type: 2,content: responseModel.data.url});
    
                        var array = this.state.imgList;
                        array[this.state.nowSelNum] = require('../img/check_video.png');
                        this.setState({imgList: array,nowSelNum: this.state.nowSelNum + 1});
                        this.endMadol();
                        toastShort('视频上传成功');
                    }
                }).catch((error) => {
                    console.warn(error);
                }).done();
    
            }
        });
    }

Log in to reply