找不到变量:FirebaseStorage

时间:2019-02-27 10:41:38

标签: reactjs firebase react-native

我想在Firebase上上传图像。当我导航到我的照片组件时,出现 ReferenceError:找不到变量:FirebaseStorage

我关注了firebase tutorial

我的代码:

// Photo Component
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

import firebase from '@firebase/app'

export default class Photo extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {

    var storage = FirebaseStorage.getInstance();
    var storageRef = storage.reference;
    var file = Uri.fromFile(File("images/image1.png"))
    var photoStored = storageRef.child("images")
    uploadTask = photoStored.putFile(file)

    return (
      <View> 
        <Text>Hello</Text>
      </View>
     )
  }
// App Component
import firebase from '@firebase/app'
import '@firebase/auth'

firebase.initializeApp({
    apiKey: "XXXXXXX",
    authDomain: "XXXXXXX",
    databaseURL: "XXXXXXX",
    projectId: "XXXXXXX",
    storageBucket: "XXXXXXX",
    messagingSenderId: "XXXXXXX"
});

export class App extends React.Component {
...
   this.props.navigation.navigate('Photo');
...

你知道是什么问题吗?

1 个答案:

答案 0 :(得分:0)

我认为您引用的是Android本机文档,并且您在这里混淆了这些内容:

使用以下代码在Firestorge上上传文件:

firebase
      .storage()
      .ref('/uploadOk.jpeg')
      .putFile(
        `${firebase.storage.Native.DOCUMENT_DIRECTORY_PATH}/ok.jpeg`
      )
      .then(successCb)
      .catch(failureCb);

有关更多详细信息,您可以参考以下链接:

here