kkost
kkost

Reputation: 3730

Firebase: pause/resume file upload

Here is what I found on the internet how to handle upload progress to the Firebase Storage.

uploadTask.on('state_changed', function(snapshot){
    // Observe state change events such as progress, pause, and resume
    // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
    var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
    console.log('Upload is ' + progress + '% done');
    switch (snapshot.state) {
      case firebase.storage.TaskState.PAUSED: // or 'paused'
        console.log('Upload is paused');
        break;
      case firebase.storage.TaskState.RUNNING: // or 'running'
        console.log('Upload is running');
        break;
    }
  }, function(error) {
    // Handle unsuccessful uploads
  }, function() {
    // Handle successful uploads on complete
    // For instance, get the download URL: https://firebasestorage.googleapis.com/...
    var downloadURL = uploadTask.snapshot.downloadURL;
  });
}

This code contains snapshot with "Pause" state value. What does this mean? Does this mean I can pause my upload and resume it in any time later on? Does somebody have any examples how to do that?

Upvotes: 1

Views: 1875

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317352

The API docs for UploadTask show that there's a pause() and a resume() method for exactly what it sounds like - pausing and resuming an upload.

Upvotes: 1

Related Questions