【问题标题】:Upload Image on Firebase Storage didn't work在 Firebase 存储上上传图片不起作用
【发布时间】:2021-07-06 01:31:30
【问题描述】:

我是 react-native 的新手,我想将图像上传到 Firebase 存储,但我有一个警告。

这是代码:

  const postBook = async () => {
    console.warn("uploaded");
    const uploadUri = image;
    let filename = uploadUri.substring(uploadUri.lastIndexOf("/") + 1);

    setUploading(true);

    try {
      await storage().ref(filename).putFile(uploadUri);
      console.log("traga");
      setUploading(false);
      Alert.alert(
        "Image uploaded",
        "Your image has been uploaded to the Firebase Cloud Storage"
      );
    } catch (e) {
      console.log(e);
    }

    setImage(null);
  };

Console.warn 在应用程序中工作,功能是 由按钮调用。

【问题讨论】:

  • 看来你uploadUri有问题。如果你检查它的值,你会得到什么?

标签: javascript firebase react-native firebase-storage


【解决方案1】:

尝试使用上传方式,先指定路径。

const filePath = "your-images-path";
const fileRef = this.storage.ref(filePath);
const task = this.storage.upload(filePath, file);

【讨论】:

    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 2020-10-05
    • 2021-07-14
    • 2021-12-23
    • 1970-01-01
    • 2021-08-18
    • 2020-12-30
    相关资源
    最近更新 更多