简体   繁体   English

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

[英]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.

相关问题 如何在本机反应中删除 Firebase 存储图像 url - How to delete Firebase Storage image by url in react native 如何使用 react-native 和 expo 将 m4a 音频文件上传到 Firebase 存储? - How does one upload an m4a audio file to Firebase Storage using react-native and expo? 如何上传 PDF Firebase 存储? - How can I upload a PDF Firebase Storage? 我正在尝试将图像上传到 firebase 存储并获取下载 url - I'm trying to upload an image to firebase storage and get the download url 如何等待firebase存储上传图片后再使用? - How to wait for firebase storage to upload image before using it? 如何在 React Native 应用程序上显示 firebase 存储中的所有图像? - How to display all images from firebase storage on React Native app? 我在哪里可以找到反应原生的 firebase 文档 - where do I find firebase documentation for react native 如何从 firebase 存储中获取图像 URL 列表并将其上传到云 firestore? - How to get a list of image URL from firebase storage and upload it to cloud firestore? 如何在 React-native 中将我的 firebase v8 代码更新为 v9? - How do i update my firebase v8 code to v9 in React-native? 将文件上传到 firebase 存储并获取 URL 以保存在反应中的数据库中 - Upload File to firebase storage and get URL to save in a database in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM