Reputation: 1885
I'm trying to prepare for the inevitability of when a user uploads to firebase storage but doesn't have an internet connection. Currently, if i use the following and turn of all internet connections it never reaches the catchError
it just waits and prints the dowloadUrl when the connection comes back.
FirebaseStorage.instance.setMaxOperationRetryTimeMillis(10);
final StorageReference ref = FirebaseStorage.instance.ref().child("AllUsers").child(uuid).child(fileName);
final StorageUploadTask uploadTask = ref.putFile(image, const StorageMetadata(contentLanguage: "en"));
Uri downloadUrl;
await uploadTask.future.then( (UploadTaskSnapshot snapshot) {
downloadUrl = snapshot.downloadUrl;
print(downloadUrl)
}).catchError((error) {
print(error);
});
Does this mean I don't have to worry about caching each image for upload later and that it's being handled? I'm assuming not but that would be great.
Update:
Adding this instead of the then catch:
try {
downloadUrl = (await uploadTask.future).downloadUrl;
print("$downloadUrl");
} catch (error) {
print(error);
}
didnt make the call after the request.
Update 2:
Tried adding the following:
FirebaseStorage.instance.setMaxUploadRetryTimeMillis(10);
FirebaseStorage.instance.setMaxOperationRetryTimeMillis(10);
FirebaseStorage.instance.setMaxDownloadRetryTimeMillis(10);
which returns E/StorageException(13068): The operation retry limit has been exceeded.
but through the console and not caught as an error in my catchError
or try catch
block.
Upvotes: 1
Views: 1927
Reputation: 5605
(This doesn't respond the exact question)
What I would do in your situation is I would save the file to disk first, and then delete it once Firebase picks it up. The flow becomes
user -> save local -> firebase -> delete local
.
Instead of
user -> firebase -> (on success) -> done
-> (on failure) -> save local -> firebase
Upvotes: 1