I have basic working code for downloading file from Firebase storage.
我有基本的工作代码下载文件从火基地存储。
String key = "gs://.../test.jpg";
File file = new File(getCacheDir() + File.separator + "test.jpg");
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference gsRef = storage.getReferenceFromUrl(key);
gsRef.getFile(file)
.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>()
{
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot)
{
Log.d("APP", "onSuccess");
}
}).addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception exception)
{
Log.d("APP", "onFailure: ", exception);
}
});
However, if above code is executed while device is not connected to Internet it takes almost 10 minutes before onFailure
event is finally triggered. In the meantime log is filling up with repeated retries:
然而,如果上面的代码是在设备未连接到互联网上执行的,那么在onFailure事件最终被触发之前几乎需要10分钟。与此同时,日志里充满了重复的重试:
02-27 21:41:07.203 12954-13288/com.example.test E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.FirebaseException: An internal error has occurred. [ <<Network Error>> ]
02-27 21:41:08.244 12954-13288/com.example.test W/ExponenentialBackoff: network unavailable, sleeping.
02-27 21:41:08.294 12954-13288/com.example.test E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.FirebaseException: An internal error has occurred. [ <<Network Error>> ]
02-27 21:41:09.405 12954-13288/com.example.test W/ExponenentialBackoff: network unavailable, sleeping.
02-27 21:41:09.485 12954-13288/com.example.test E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.FirebaseException: An internal error has occurred. [ <<Network Error>> ]
Is there a way I can shorten (customize) retry period and trigger onFailure
event sooner?
是否有一种方法可以缩短重试周期并更快触发onFailure事件?
1 个解决方案
#1
7
Yes, you can configure the timeout for uploads, downloads, and other operations using the setMaximum{OPERATION}RetryTimeMillis()
methods:
是的,您可以使用setMaximum{OPERATION}RetryTimeMillis()方法配置上传、下载和其他操作的超时:
FirebaseStorage storage = FirebaseStorage.getInstance();
storage.setMaxDownloadRetryTimeMillis(60000); // wait 1 min for downloads
storage.setMaxOperationRetryTimeMillis(10000); // wait 10s for normal ops
storage.setMaxUploadRetryTimeMillis(120000); // wait 2 mins for uploads
See the reference docs for more,
更多信息请参阅参考文档,
#1
7
Yes, you can configure the timeout for uploads, downloads, and other operations using the setMaximum{OPERATION}RetryTimeMillis()
methods:
是的,您可以使用setMaximum{OPERATION}RetryTimeMillis()方法配置上传、下载和其他操作的超时:
FirebaseStorage storage = FirebaseStorage.getInstance();
storage.setMaxDownloadRetryTimeMillis(60000); // wait 1 min for downloads
storage.setMaxOperationRetryTimeMillis(10000); // wait 10s for normal ops
storage.setMaxUploadRetryTimeMillis(120000); // wait 2 mins for uploads
See the reference docs for more,
更多信息请参阅参考文档,