【问题标题】:react-native: uploaded video it saves like imagereact-native:上传的视频像图片一样保存
【发布时间】:2017-07-23 08:46:30
【问题描述】:

当我上传视频时,我正在使用 react-native-camera-roll-picker,但这是来自 assets-library 的 mp4 文件我如何上传视频这是我的代码块,如何解决问题。

let videoFile = {
name : "1488523111.mp4"
type : "video/mp4"
uri : "assets-library://asset/asset.MP4?id=14E53F62-798B-4F26-9A70-A0755CEC9760&ext=MP4"
}


  var xhr = new XMLHttpRequest();
  xhr.open('POST', url);
 var formdata = new FormData();
 formdata.append('name', 'test');
 formdata.append('file', videoFile);
 xhr.setRequestHeader('Cache-Control', 'no-cache');
 xhr.setRequestHeader('Authorization', 'Bearer ' + this.state.token);
  xhr.send(formdata);

【问题讨论】:

  • 你问这个问题已经两年了,解决了吗?如何?请...

标签: reactjs react-native react-native-ios


【解决方案1】:

先转成Base64

setVideoToUpload(video){
    let platform = (Platform.OS === 'ios') ? 'ios' : 'android'
    let originalHeight = video.height
    let originalWidth = video.width
    let path = video.uri;
    var filename = Date.now().toString();



        MovToMp4.convertMovToMp4(path, filename + ".mp4", function (data) {
            //here you can upload the video...

            let videoToUpload = [{
                data: data,
                width: originalWidth ,
                height: originalHeight,
                imageOrVideo: 'video',
                type: '.mp4',
                platform: 'ios',
                duration: video.duration,
                uri: this.props.route.lastCaptured.path,

            }]

        });

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 2018-06-08
    • 2017-06-29
    • 2020-11-26
    • 2018-11-24
    • 2019-04-28
    • 1970-01-01
    相关资源
    最近更新 更多