I initialise my application this way and it work perfectly well as i can use the authentification.
import { initializeApp} from "firebase/app";
import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
import { getAnalytics } from "firebase/analytics";
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import { requestTrackingPermissionsAsync } from "expo-tracking-transparency";
import { Settings } from "react-native-fbsdk-next";
const firebaseConfig = {
apiKey: "",
authDomain: "-..",
projectId: "-",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
However, when i try to use the firebase storage with this function
import storage from '@react-native-firebase/storage'
export const UploadFile = async(file_uri,name,bucket) => {
return new Promise((resolve, reject) => {
try{
const parts = file_uri.split(/[/\]/)
const basename = parts[parts.length - 1]
if(bucket){
bucket = firebase.app().storage('gs://'+bucket+'.appspot.com').ref(basename)
}else{
bucket = storage().ref(basename)
}
bucket.putFile(file_uri)
resolve(bucket)
}catch(error){
console.log('Error when uploading the file '+error)
reject(error)
}
});
}
I get the error
No Firebase App ‘[DEFAULT]’ has been created – call firebase.initializeApp()
for the line bucket = storage().ref(basename)
I tried to pass it app as argument as it’s a possible argument but it didn’t work either.
I tried other solution found on stackoverflow, github, reddit, etc without success either
Thank you for your help
2
Answers
I don't know why the firebase doc is never up to date and the working solution are never the ones on the doc. Anyway, the solution : Get the storage this way
And Upload function :
try this