File

src/app/services/firebase/storage/firebase-storage.service.ts

Description

A service to up and download files from Firebase storage

Example

Index

Properties
Methods

Constructor

constructor(afStorage: AngularFireStorage)

Constructor

Parameters :
Name Type Optional Description
afStorage AngularFireStorage

AngularFire Storage

Methods

pushUpload
pushUpload(event: string, upload: Upload)

Upload images to Firebase storage

Parameters :
Name Type Optional Description
event string

Event ID

upload Upload

Uploadfile

Properties

Private log
log:
Default value : Log.create('FirebaseStorageService')

Logger

Public uploads
uploads: Observable<[]>
Type : Observable<[]>

Upload files

import { Injectable } from '@angular/core';
import {
  AngularFireStorage,
  AngularFireStorageReference,
  AngularFireUploadTask
} from 'angularfire2/storage';
import { Log } from 'ng2-logger';
import { Observable } from 'rxjs/Observable';

import { Upload } from '../../../classes/upload-file';

/**
 * A service to up and download files from Firebase storage
 * @author Daniel Sogl
 */
@Injectable()
export class FirebaseStorageService {
  /** Logger */
  private log = Log.create('FirebaseStorageService');

  /** Upload files */
  public uploads: Observable<Upload[]>;

  /**
   * Constructor
   * @param  {AngularFireStorage} afStorage AngularFire Storage
   */
  constructor(private afStorage: AngularFireStorage) {
    this.log.color = 'green';
    this.log.d('Service injected');
  }

  /**
   * Upload images to Firebase storage
   * @param  {string} event Event ID
   * @param  {Upload} upload Uploadfile
   * @returns {AngularFireUploadTask}
   */
  pushUpload(event: string, upload: Upload): AngularFireUploadTask {
    const storageRef: AngularFireStorageReference = this.afStorage.ref(
      `events/${event}/${upload.file.name}`
    );
    return storageRef.put(upload.file);
  }
}

results matching ""

    No results matching ""