在React Native中使用FormData上传视频 [英] Uploading videos using formdata in react native

查看:1136
本文介绍了在React Native中使用FormData上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人通过React Native Formdata()成功上传了视频吗?下面的代码尝试从相机胶卷URI上传.mov文件,但实际上仅上传了视频的第一帧(JPEG).这是什么问题?

Has anyone successfully uploaded a video via React Native Formdata()? The code below attempts to upload a .mov file from the camera roll URI but in fact only the first frame of the video (a JPEG) gets uploaded. What's the issue here?

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不会为带有资源库URI的视频返回正确的流.图片似乎工作正常.不过,在提交问题之前,我需要更深入地研究.

Had the same issue. Looks like React Native does not return the correct stream for videos with asset library URIs. Pictures seem to work fine. I would need to dig deeper before submitting an issue though.

我建议您看看 react-native-fetch-blob 改进的fetch polyfill具有Blob支持.此实现可以很好地处理相机胶卷中的视频.另外,使用此模块所需的更改很小(包括polyfill,使用RNFetchBlob.wrap包装URI).

I suggest you take a look at react-native-fetch-blob, which provides an improved fetch polyfill with Blob support. This implementation handles videos from the camera roll just fine. Also, the changes needed to use this module are minimal (include the polyfill, wrap URI with RNFetchBlob.wrap).

这篇关于在React Native中使用FormData上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆