我需要在后台上传大型视频文件。 实现这一目标的最佳方法是什么?
我尝试使用这个库 ( react-native-background-upload )。但问题是,我无法随视频文件一起发送任何其他数据。 API 需要以下数据:
{
projectId: number,
title: string,
video: file,
};
这是使用库使用 multipart
发送文件的代码片段:
const options = {
url: url,
path: pathToVideoFile,
method: 'POST',
field: 'video',
type: 'multipart',
};
有没有我可以使用的替代品?可以react-native-background-fetch用于此用例?
最佳答案
在react-native-background-upload
您可以在 options
中使用 parameters
来发送额外的数据
Additional form fields to include in the HTTP request. Only used when type: 'multipart
const options = {
url: url,
path: pathToVideoFile,
method: 'POST',
field: 'video',
type: 'multipart',
parameters : {
key1: "value1",
key2: "value2",
}
};
你可以在这里看到所有选项参数 here
关于react-native - 在 native react 中在后台上传大型视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69249682/