gpt4 book ai didi

firebase - 如何将 React-Native-camera 拍摄的图像上传到 Firebase 存储?

转载 作者:行者123 更新时间:2023-12-05 03:03:30 25 4
gpt4 key购买 nike

  takePicture = async function() {
if (this.camera) {
const options = { quality: 0.5, base64: true, mirrorImage: true };
const data = await this.camera.takePictureAsync(options)

this.setState({path: data.uri})
}

}

takePicture 是捕获图像的函数。现在我想保存捕获的图像并将其上传到 Firebase 存储。

this.setState({path: data.uri}) 更新点击图像位置的路径。

如何使用 React Native Fetch Blob 将我的图像上传到 Firebase 存储中?请帮忙

我目前正在使用 react-native-camera - ^1.6.3和 Firebase - ^5.0.3

最佳答案

您可以使用此示例代码将您的图片上传到特定的 api。

var data = new FormData();

data.append('file', { uri: data.uri, name: 'picture.jpg', type: 'image/jpg' });
// Create the config object for the POST
const config = {
method: 'POST',
body: data
};
fetch('URL', config).then(responseData => {
// Log the response form the server // Here we get what we sent to Postman
back
console.log(responseData);
})
.catch(err => { console.log(err); });

希望对你有帮助。

关于firebase - 如何将 React-Native-camera 拍摄的图像上传到 Firebase 存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53864677/

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