【问题标题】:i m stuck in upload image on firebase cloud firestore. Can anyone help me .?我被困在 firebase cloud firestore 上的上传图片中。谁能帮我 。?
【发布时间】:2020-12-22 12:26:22
【问题描述】:
const { user_id, username } = this.props;
const { imagePath } = this.state;

const fileExtension = imagePath.split(".").pop();
console.log("EXT: " + fileExtension);

var uuid = uuidv4();

const fileName = `${uuid}.${fileExtension}`;
console.log("fiile name ---> " + fileName);

this.setState({ profile_image : fileName });

export const addManualContact = 
    (username, profile_image ) => {
         firebase.firestore().collection('user').doc(`${username}`).collection('contacts').add({ profile_image: profile_image }) }

【问题讨论】:

  • 这里没有将文件上传到 Firebase。你已经尝试过什么了吗?如果没有,我建议从文档开始。
  • 是的,我在我的问题中进行了编辑。
  • 您希望这段代码现在做什么?而它的作用是什么?
  • 我需要上传图片到云火库。并下载并在另一个屏幕上显示。所以请帮助我如何在“Cloud firestore”上上传图像以及如何下载和显示图像......
  • this 你在找什么吗?

标签: javascript firebase react-native google-cloud-firestore


【解决方案1】:

问题是我的图书馆import ImagePicker from "react-native-image-crop-picker";

这里是函数:

//Here is take photo from gallery 
 takePhotoFromCamera2 = () => {
    ImagePicker.openCamera({
      width: 300,
      height: 400,
      cropping: true,
    }).then((image2) => {
      this.setState({ profile_image2: image.path });
      console.log(image2);
      this.setState({
        image2: {
          uri: image2.path,
          width: image2.width,
          height: image2.height,
          mime: image2.mime,
        },
        images: null,
      });
    });
  };

然后我像这样在 Firestore 中上传图片:

firebase.firestore()
        .collection("user")
        .doc(`${username}`)
        .update({ profile_image: profile_image });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-11
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 2022-08-10
    相关资源
    最近更新 更多