首页 > 解决方案 > 将 Expo Camera 录制的视频上传到服务器

问题描述

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

标签: react-nativeexpovideo-upload

解决方案


好的,所以你有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
};

推荐阅读