import { Inject , Injectable , InjectionToken , NgZone , Optional , PLATFORM_ID } from '@angular/core' ; import { createStorageRef } from './ref' ; import { ɵAngularFireSchedulers } from '@angular/fire' ; import { FirebaseOptions } from 'firebase/app' ; import { ɵfirebaseAppFactory , FIREBASE_APP_NAME , FIREBASE_OPTIONS , ɵcacheInstance } from '@angular/fire/compat' ; import { UploadMetadata } from './interfaces' ; import 'firebase/compat/storage' ; import firebase from 'firebase/compat/app' ; import { AppCheckInstances } from '@angular/fire/app-check' ; export const BUCKET = new InjectionToken < string > ( 'angularfire2.storageBucket' ) ; export const MAX_UPLOAD_RETRY_TIME = new InjectionToken < number > ( 'angularfire2.storage.maxUploadRetryTime' ) ; export const MAX_OPERATION_RETRY_TIME = new InjectionToken < number > ( 'angularfire2.storage.maxOperationRetryTime' ) ; type UseEmulatorArguments = Parameters < firebase . storage . Storage [ 'useEmulator' ] > ; export const USE_EMULATOR = new InjectionToken < UseEmulatorArguments > ( 'angularfire2.storage.use-emulator' ) ; /**
 * AngularFireStorage Service
 *
 * This service is the main entry point for this feature module. It provides
 * an API for uploading and downloading binary files from Cloud Storage for
 * Firebase.
 */ @ Injectable ( { providedIn : 'any' } ) export class AngularFireStorage { public readonly storage : firebase . storage . Storage ; constructor ( @ Inject ( FIREBASE_OPTIONS ) options , @ Optional ( ) @ Inject ( FIREBASE_APP_NAME ) name , @ Optional ( ) @ Inject ( BUCKET ) storageBucket , @ Inject ( PLATFORM_ID ) platformId , zone , schedulers , @ Optional ( ) @ Inject ( MAX_UPLOAD_RETRY_TIME ) maxUploadRetryTime , @ Optional ( ) @ Inject ( MAX_OPERATION_RETRY_TIME ) maxOperationRetryTime , @ Optional ( ) @ Inject ( USE_EMULATOR ) _useEmulator , @ Optional ( ) _appCheckInstances ) { const app = ɵfirebaseAppFactory ( options , zone , name ) ; this . storage = ɵcacheInstance ( `${ app . name }.storage.${ storageBucket }` , 'AngularFireStorage' , app . name , ( ) => { const storage = zone . runOutsideAngular ( ( ) => app . storage ( storageBucket || undefined ) ) ; const useEmulator = _useEmulator as UseEmulatorArguments | null ; if ( useEmulator ) { storage . useEmulator ( ... useEmulator ) ; } if ( maxUploadRetryTime ) { storage . setMaxUploadRetryTime ( maxUploadRetryTime ) ; } if ( maxOperationRetryTime ) { storage . setMaxOperationRetryTime ( maxOperationRetryTime ) ; } return storage ; } , [ maxUploadRetryTime , maxOperationRetryTime ] ) ; } ref ( path ) { return createStorageRef ( this . storage . ref ( path ) ) ; } refFromURL ( path ) { return createStorageRef ( this . storage . refFromURL ( path ) ) ; } upload ( path , data , metadata ? ) { const storageRef = this . storage . ref ( path ) ; const ref = createStorageRef ( storageRef ) ; return ref . put ( data , metadata ) ; } }