I'm setting up a file uploader that will upload images to my firebase storage. I am using React-Redux-Firebase to do all of this. According to the docs, I should be able to use either the uploadFiles or uploadFile functions that come from props.firebase using firebaseConnect or getFirebase(). When I try this I get the error: Uncaught Error: Firebase storage is required to upload files.
export const addImage = (image, callback = () => {}) => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const firebase = getFirebase();
const imagesPath = "images";
firebase.uploadFile(imagesPath, image).then(uploadTaskSnapshot => {
console.log("uploadTaskSnapshot", uploadTaskSnapshot);
});
dispatch({ type: "ADDED_IMAGE", image });
};
};
The function exists when I try to console.log it. But its almost like my storage isn't set up. I have checked my firebase console and it definitely exists. I have also checked my api key settings and the storage bucket variable is correct.
Here is the set up code I am using in my index.js file and also my firebaseConfig file.
Index.js :
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import { createStore, applyMiddleware, compose } from "redux";
import rootReducer from "./store/reducers/rootReducer";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import { reduxFirestore, getFirestore } from "redux-firestore";
import { reactReduxFirebase, getFirebase } from "react-redux-firebase";
import fbConfig from "./config/fbConfig";
require("dotenv").config();
const store = createStore(
rootReducer,
compose(
applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
reduxFirestore(fbConfig),
reactReduxFirebase(fbConfig, { useFirestoreForProfile: true, userProfile: "users", attachAuthIsReady: true })
)
);
store.firebaseAuthIsReady.then(() => {
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
});
fbConfig.js :
import firebase from "firebase/app";
import "firebase/firestore";
import "firebase/auth";
// Initialize Firebase
var config = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID
};
firebase.initializeApp(config);
firebase.firestore();
console.log("firebase", firebase);
export default firebase;