在 React Native 中使用表单数据上传视频
Uploading videos using formdata in react native
有没有人通过 React Native Formdata() 成功上传视频?下面的代码尝试从相机胶卷 URI 上传 .mov 文件,但实际上只上传了视频的第一帧(JPEG)。这里有什么问题?
var movVideo = {
uri: uriFromCameraRoll,
type: 'video/quicktime',
name: 'something.mov',
};
var body = new FormData();
body.append('video', movVideo);
body.append('title', 'A beautiful video!');
fetch('https://mysite/upload_asset', {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
},
body: body,
}).then((response) => response.json())
.then((responseJson) => {
//only the first frame of the video got uploaded
console.log(responseJson);
});
有同样的问题。看起来 React Native 没有 return 具有资产库 URI 的视频的正确流。图片似乎工作正常。不过,在提交问题之前我需要更深入地挖掘。
我建议您看一下 react-native-fetch-blob
,它提供了改进的 fetch
polyfill,支持 Blob。此实现可以很好地处理相机胶卷中的视频。此外,使用此模块所需的更改很少(包括 polyfill,用 RNFetchBlob.wrap 包装 URI)。
有没有人通过 React Native Formdata() 成功上传视频?下面的代码尝试从相机胶卷 URI 上传 .mov 文件,但实际上只上传了视频的第一帧(JPEG)。这里有什么问题?
var movVideo = {
uri: uriFromCameraRoll,
type: 'video/quicktime',
name: 'something.mov',
};
var body = new FormData();
body.append('video', movVideo);
body.append('title', 'A beautiful video!');
fetch('https://mysite/upload_asset', {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
},
body: body,
}).then((response) => response.json())
.then((responseJson) => {
//only the first frame of the video got uploaded
console.log(responseJson);
});
有同样的问题。看起来 React Native 没有 return 具有资产库 URI 的视频的正确流。图片似乎工作正常。不过,在提交问题之前我需要更深入地挖掘。
我建议您看一下 react-native-fetch-blob
,它提供了改进的 fetch
polyfill,支持 Blob。此实现可以很好地处理相机胶卷中的视频。此外,使用此模块所需的更改很少(包括 polyfill,用 RNFetchBlob.wrap 包装 URI)。