gpt4 book ai didi

android - 如何在 React-native 中使用视频文件路径将视频存储在 firebase 存储中

转载 作者:行者123 更新时间:2023-11-29 02:34:55 25 4
gpt4 key购买 nike

当我获得视频路径时,我该怎么做才能使用 react-native 将该视频存储在 firebase 存储中?

file://storage/emulated/0/DCIM/1234.MP4.... 我得到了那个路径

这是我创建录像机并获取录制的视频文件路径的代码。

import Camera from 'react-native-camera';

<Camera
captureMode={this.state.captureMode}
captureAudio={this.state.captureAudio}
captureTarget={this.state.captureTarget}
ref="camera"
style={styles.preview}>

{ toggle? <TouchableOpacity onPress={() =>this._startRecord()}>
<Image style={styles.clickimage}
source={require('../images/icon_record_stop.png')} />
</TouchableOpacity>
: <TouchableOpacity onPress={() =>this._endVideo()}>
<Image style={styles.clickimage}
source={require('../images/clickimage.png')} />
</TouchableOpacity>
}
</Camera>


_startRecord() {
this.refs.camera.capture({mode: Camera.constants.CaptureMode.video})
.then((data) => {
this.setState({
storagepathdata:data.path
});
// var path = data.path;
})
.catch((err) => console.log(err))
}

_endVideo() {
this.refs.camera.stopCapture()
.then((response) => {
alert(this.state.storagepathdata);

// here storagepathdata is a file path so what i do to store that video on firebase?
}

最佳答案

在 fs.readFile(video, 'base64') 中设置视频路径,它将返回 blob 然后设置 blob 和用于视频的 contentType : 'video/mp4' 和 fter 文件上传 firebase 返回视频 URL 以响应最后的 promise

不要忘记安装和导入

 import RNFetchBlob from 'react-native-fetch-blob';

const sessionId = new Date().getTime();
const Blob = RNFetchBlob.polyfill.Blob;
const fs = RNFetchBlob.fs;
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
window.Blob = Blob;
let uploadBlob = null;
let mime = 'video/mp4';
const firebaseRef = firebase.storage().ref("video").child(`${sessionId}`);
return fs.readFile(video, 'base64')
.then((data) => {
console.log("data", data)
return Blob.build(data, { type: `${mime};BASE64` })
})
.then((blob) => {
console.log("blob", blob)
uploadBlob = blob;
return firebaseRef.put(blob, { contentType: mime })
})
.then((res) => {
console.log("res", res)
uploadBlob.close();
return firebaRef.getDownloadURL()
})
.then((res) => {
console.log("URL", res)

})

关于android - 如何在 React-native 中使用视频文件路径将视频存储在 firebase 存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47631336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com