将使用 Expo Camera 录制的视频上传到服务器
Uploading video recorded with Expo Camera to server
我正在使用expo camera录制视频,录制的视频保存在缓存中,我想将录制的视频上传到服务器。我有视频的 uri,但要将其上传到服务器,我需要文件本身。如何将文件添加到请求正文中? (我不能使用 rn-fletch-blob 或 react-native-fs,因为它是一个 expo 项目)
好的,所以你有 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
};
我正在使用expo camera录制视频,录制的视频保存在缓存中,我想将录制的视频上传到服务器。我有视频的 uri,但要将其上传到服务器,我需要文件本身。如何将文件添加到请求正文中? (我不能使用 rn-fletch-blob 或 react-native-fs,因为它是一个 expo 项目)
好的,所以你有 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
};