Firebase storage handling network interruptions when download in progress

…衆ロ難τιáo~ 提交于 2019-11-28 11:49:50

Uploads, Downloads and other operations are intended to automatically retry and shield you from temporary interruptions. There is a configurable timeout that will end (fail) the operation if it cannot transfer a packet in that time. You can set this with:

//if we get interrupted for more than 2 seconds, fail the operation.
FirebaseStorage.getInstance().setMaxUploadRetryTimeMillis(2000);

There are different timeouts for uploads, downloads and other operations.

With uploads, you can attempt to resume the upload from where you left off (if your source was a file) even if it was interrupted. To do this you need to obtain the "upload session uri" from the upload task.

task.addOnFailureListener(new OnFailureListener {
  @Override
  public void OnFailure(Exception error) {
     Uri uploadsession = task.getSnapshot().getUploadSessionUri();
     //if you want to retry later, feed this uri as the last parameter
     // to putFile(uri, metadata, uri)
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!