我正在使用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);
答案 0 :(得分:0)
首先将其转换为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,
}]
});
}