如何将React-Native相机拍摄的图像上传到Firebase存储? [英] How do I upload an image taken by React-Native-camera to Firebase storage?

查看:60
本文介绍了如何将React-Native相机拍摄的图像上传到Firebase存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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存储.

takePicture is the function to capture the image. Now I want to save the captured image and upload it to Firebase storage.

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

this.setState({path: data.uri}) updates the path to clicked Image's location.

如何使用react native fetch blob将图像上传到Firebase存储中?请帮助

How do I use react native fetch blob to upload my image in firebase storage? Please help

我当前正在使用react-native-camera-^ 1.6.3和firebase-^ 5.0.3

I'm currently using react-native-camera - ^1.6.3 and firebase - ^5.0.3

推荐答案

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

You can to using this sample code to upload your picture to the specific 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); });

希望这对您有所帮助.

这篇关于如何将React-Native相机拍摄的图像上传到Firebase存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆