1

我正在使用该react-redux-firebase软件包并尝试将文件上传到存储。

我正在使用withFirebaseHOC 并且得到了this.prop.firebase但是,this.props.firebase.storage并且this.props.firebase.storage()undefined.

当我打电话时,this.props.firebase.uploadFiles(file)我收到以下错误:Firebase storage is required to upload files

这是我的index.js

...
import { ReactReduxFirebaseProvider } from 'react-redux-firebase'
import { createFirestoreInstance, getFirestore, reduxFirestore } from 'redux-firestore'
import firebase from './config/firebaseConfig';

const rrfConfig = { userProfile: 'users', useFirestoreForProfile: true };

const store = createStore(rootReducer,
    compose(
        applyMiddleware(thunk.withExtraArgument({ getFirestore })),
        reduxFirestore(firebase),
    )
);

const rrfProps = {
    firebase,
    config: rrfConfig,
    dispatch: store.dispatch,
    createFirestoreInstance
};

ReactDOM.render(
    <Provider store={store}>
        <ReactReduxFirebaseProvider {...rrfProps}>
            <App />
        </ReactReduxFirebaseProvider>
    </Provider>, document.getElementById('root')
);

这是./config/firebaseConfig

import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/auth'

const firebaseConfig = {
    apiKey: "#######",
    authDomain: "#######.firebaseapp.com",
    databaseURL: "https://######.firebaseio.com",
    projectId: "######",
    storageBucket: "########.appspot.com",
    messagingSenderId: "##########",
    appId: "#:#########:web:############"
};
firebase.initializeApp(firebaseConfig);
export default firebase;

最后是我的组件:

import React from 'react'
import {withFirebase} from 'react-redux-firebase'
import {compose} from "redux";

class DragAndDrop extends React.Component {

    onDragOver(e){
        e.preventDefault();
        console.log('over');
    }

    onDragLeave(){
        console.log('leave');
    }

    handleDrop(e){
        e.preventDefault();
        let dt = e.dataTransfer;
        let files = dt.files;

        console.log(this.props.firebase.uploadFiles('/merchants', files));
    }

    uploadFile(file){
        console.log(this.props.firebase.uploadFile(
            '/merchants',
            file
        ))
    }

    render() {
        console.log(this.props);
        return (
            <div
                onDragOver={this.onDragOver}
                onDragEnter={this.onDragOver}
                onDragLeave={this.onDragLeave}
                onDrop={this.handleDrop.bind(this)}
                className="dnd">Drag And Drop</div>
        )
    }
}

export default compose(
    withFirebase
)(DragAndDrop);
4

1 回答 1

3

firebase/storage导入文件后添加导入firebase/auth./config/firebaseConfig然后重试:)

于 2019-06-03T01:32:44.360 回答