我正在使用 expo camera 录制视频,录制的视频保存在缓存中,我想将录制的视频上传到服务器。我有视频的 uri,但要将其上传到服务器,我需要文件本身。如何将文件添加到请求正文中? (我不能使用 rn-fletch-blob 或 react-native-fs,因为它是一个世博项目)
答案 0 :(得分:0)
好的,您有 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
};