react-native - 将 Expo Camera 录制的视频上传到服务器
问题描述
我正在使用 expo 相机录制视频,录制的视频保存在缓存中,我想将录制的视频上传到服务器。我有视频的 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
};
推荐阅读
- sql - SQL Server:如何根据查询返回的列更新表?
- session - 在 Coldfusion 中更改密码时如何注销其他会话
- tensorflow - IndexError:使用 np.argmax 函数时列表索引超出范围
- reactjs - 没有模块的 Typescript 和 React - 找不到名称“React”
- node.js - 用 mongoose 中的 id 数组更新嵌套数组
- swift - VLCKit:当我停止视频时,无法将 VLCMediaPlayer.position 重置为 0
- java - 甚至未列出的所有内容都在使用 recyclerView 滚动
- java - 如何根据每行的分数对矩阵进行排名?
- powershell - 为什么我收到警告“变量 'lastUpdate' 已分配但从未使用过。” 在这个 PowerShell
- python - 获取所有子串频率忽略空间