[英]How do I upload an image taken by React-Native-camera to Firebase storage?
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 is the function to capture the image. takePicture 是捕获图像的功能。 Now I want to save the captured image and upload it to Firebase storage.现在我想保存捕获的图像并将其上传到 Firebase 存储。
this.setState({path: data.uri}) updates the path to clicked Image's location. this.setState({path: data.uri}) 更新点击图像位置的路径。
How do I use react native fetch blob to upload my image in firebase storage?如何使用 react native fetch blob 将我的图像上传到 firebase 存储中? Please help请帮忙
I'm currently using react-native-camera - ^1.6.3 and firebase - ^5.0.3我目前正在使用 react-native-camera - ^1.6.3 和 firebase - ^5.0.3
You can to using this sample code to upload your picture to the specific api.您可以使用此示例代码将您的图片上传到特定的 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); });
Hope this help you.希望这对你有帮助。
async function uploadFile() {
const data = new FormData();
data.append('file', { uri: data.uri, name: 'anyname.jpg', type: 'image/jpg' });
const response = await axios.post('URL', data);
const { id, url } = response.data;
}
It Dit worked, Thanks.它奏效了,谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.