Can't use try catch Firebase Storage [c# Unity]

453 views
Skip to first unread message

media...@gmail.com

unread,
Nov 1, 2018, 3:47:05 AM11/1/18
to Firebase Google Group
Hey,

I have been wanting to check and see if a file exists in firebase Storage
but according to documentation only way to do is to check for exceptions.
But Firebase doesn't seem to obey that . i tried the following code
it is not goiing into either of if statements nor is it reporting a error

instead logs a this in console StorageReference gs://titlez-fae89.appspot.com/bookpics/prod123.png GetDownloadUrl. failed Not Found.  Could not get object  Http Code: 404.



            try
            {
                bookImageRef.GetDownloadUrlAsync().ContinueWith(task =>
                {
                    Debug.Log(task.Result);

                    if (task.IsFaulted
                        || task.IsCanceled)
                    {

                        Debug.LogError("Download URL: " + task.Result);
                        // use default.png

                        // ... now download the file via WWW or UnityWebRequest.
                    }
                    else if (task.IsCompleted)
                    {
                        Debug.Log("Download URL: " + task.Result);
                        //   GetBookImageFromDB(Productcode, out _image, ImageDownloadLocDetails.DownloadDefault);
                    }
                });

how do I catch the error so I can check if the image exists and perform a particular function if it does and another if it doesnt

Please feel free to let me know if you found it hard to understand my query
Thanks & regards

Shawn Kuang

unread,
Dec 12, 2018, 6:45:01 PM12/12/18
to Firebase Google Group
Hi,

You can check task.Exception when task.IsFault is true.   Please take a look of the following sample code.

The error code should be ErrorObjectNotFound.

Hope this helps!
Shawn
Reply all
Reply to author
Forward
0 new messages