0

我想在录制视频时(而不是在录制后)将数据块上传到服务器。我尝试使用react-native-cameraor react-native-vision-camera

但据我所知,recordAsync方法只能解决录制视频的最终版本。

有没有什么聪明的方法可以在录制过程中获取视频块或流。

还是我应该使用 react-native-fs 或rn-fetch-blob类似的东西?

== 更新 ==

我可能可以像在下面的链接中那样实现它。

https://medium.com/react-native-training/build-youtube-alike-livestreams-with-react-native-8dde24adf543

4

1 回答 1

0

如果您的问题是关于将大文件上传到服务器,也许您可​​以使用react-native-background-upload并显示进度通知,即使应用程序处于后台,这也会上传文件。

还有一个包可以通过将文件分成多个块来进行块上传:react-native-chunk-upload

import ChunkUpload from 'react-native-chunk-upload';

const chunk = new ChunkUpload({
    path: response.path, // Path to the file
    size: 10095, // Chunk size (must be multiples of 3)
    fileName: response.fileName, // Original file name
    fileSize: response.size, // Original file size

    // Errors
    onFetchBlobError: (e) => console.log(e),
    onWriteFileError: (e) => console.log(e),
});

chunk.digIn(this.upload.bind(this));

upload(file, next, retry, unlink) {
    const body = new FormData();

    body.append('video', file.blob); // param name

    axios.post('url', body, {
        headers: {
            "Content-Type": "multipart/form-data",
            "Accept": 'application/json',


            // Customize the headers
            "x-chunk-number": file.headers["x-chunk-number"],
            "x-chunk-total-number": file.headers["x-chunk-total-number"],
            "x-chunk-size": file.headers["x-chunk-size"],
            "x-file-name": file.headers["x-file-name"],
            "x-file-size": file.headers["x-file-size"],
            "x-file-identity": file.headers["x-file-identity"]
        }
    }).then((res) => {
        ...
      })
于 2022-01-12T05:03:52.503 回答