2017-03-03 8 views
1

Ich benutze react-native-Kamera-Roll-Picker, wenn ich das Video hochladen es wie Bild hochladen, aber das ist mp4-Datei von Assets-Bibliothek, wie kann ich hochladen Video Dies ist mein Code Chunk, Wie man das Problem löst.react-native: Video hochgeladen es speichert wie Bild

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); 

Antwort

0

wandeln es in Base64 erste

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, 

      }] 

     }); 

}