微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 Expo Camera 录制的视频上传到服务器

如何解决将 Expo Camera 录制的视频上传到服务器

我正在使用 expo camera 录制视频,录制的视频保存在缓存中,我想将录制的视频上传到服务器。我有视频的 uri,但要将其上传到服务器,我需要文件本身。如何将文件添加到请求正文中? (我不能使用 rn-fletch-blob 或 react-native-fs,因为它是一个世博项目)

解决方法

好的,您有 uri

现在我们必须创建一个 form-data,因为它是一个文件。

要创建 form-data,请按照以下步骤操作

创建一个函数

const CreateFormData = (uri) => {
  // Here uri means the url of the video you captured
  const form = new FormData();
  form.append("File",{
    name: "SampleVideo.mp4",uri: uri,type: "video/mp4",});

  // Now perform a post request here by adding this form in the body part of the request
  // Then you can handle the file you sent in the backend i.e server
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。