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/