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:
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?
Yes, you can configure the timeout for uploads, downloads, and other operations using the setMaximum{OPERATION}RetryTimeMillis()
methods:
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,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With