找不到变量:FirebaseStorage



我想在firebase上上传图像。当我导航到我的照片组件时,我有 ReferenceError:找不到变量:firebasestorage

我遵循Firebase教程

我的代码:

// 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');
...

你知道有什么问题吗?

我认为您正在推荐本机Android文档,并且您在这里混合了这些内容:

使用以下代码上载文件上的文件:

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

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

https://github.com/invertase/react-native-firebase-docs/blob/master/docs/storage/storage/Reference/Reference.md#putfile

相关内容

  • 没有找到相关文章

最新更新