Go to console

Represents the process of uploading an object. Allows you to monitor and manage the upload.

Index

Properties

Methods

Properties

snapshot

A snapshot of the current task state.

Methods

cancel

  • cancel(): boolean
  • Cancels a running task. Has no effect on a complete or failed task.

    Returns boolean

    True if the cancel had an effect.

catch

  • catch(onRejected: function): Promise<any>
  • Equivalent to calling then(null, onRejected).

    Parameters

    • onRejected: function
        • (a: Error): any
        • Parameters

          • a: Error

          Returns any

    Returns Promise<any>

on

  • on(event: TaskEvent, nextOrObserver?: Observer<UploadTaskSnapshot> | null | function, error?: function | null, complete?: function | null): Function
  • Listens for events on this task.

    Events have three callback functions (referred to as next, error, and complete).

    If only the event is passed, a function that can be used to register the callbacks is returned. Otherwise, the callbacks are passed after the event.

    Callbacks can be passed either as three separate arguments or as the next, error, and complete properties of an object. Any of the three callbacks is optional, as long as at least one is specified. In addition, when you add your callbacks, you get a function back. You can call this function to unregister the associated callbacks.

    example

    Pass callbacks separately or in an object.

    var next = function(snapshot) {};
    var error = function(error) {};
    var complete = function() {};
    
    // The first example.
    uploadTask.on(
        firebase.storage.TaskEvent.STATE_CHANGED,
        next,
        error,
        complete);
    
    // This is equivalent to the first example.
    uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
      'next': next,
      'error': error,
      'complete': complete
    });
    
    // This is equivalent to the first example.
    var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
    subscribe(next, error, complete);
    
    // This is equivalent to the first example.
    var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
    subscribe({
      'next': next,
      'error': error,
      'complete': complete
    });
    example

    Any callback is optional.

    // Just listening for completion, this is legal.
    uploadTask.on(
        firebase.storage.TaskEvent.STATE_CHANGED,
        null,
        null,
        function() {
          console.log('upload complete!');
        });
    
    // Just listening for progress/state changes, this is legal.
    uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
      var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
      console.log(percent + "% done");
    });
    
    // This is also legal.
    uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
      'complete': function() {
        console.log('upload complete!');
      }
    });
    example

    Use the returned function to remove callbacks.

    var unsubscribe = uploadTask.on(