Exemplo n.º 1
0
        public void UploadImage(byte[] file, string id, bool isThumb)
        {
            Firebase.Storage.StorageReference picRef = storage_ref.Child("Pictures/" + id + ".png");

            try
            {
                picRef.PutBytesAsync(file)
                .ContinueWith((task) =>
                {
                    if (task.IsFaulted || task.IsCanceled)
                    {
                        Debug.Log(task.Exception.ToString());
                    }
                    else
                    {
                        //success
                    }
                });
            }
            catch (Exception e)
            {
                Debug.Log(e.ToString());
            }
            SaveImage(file, id, isThumb);
        }
Exemplo n.º 2
0
        public void GetPictureFor(string id, Action <byte[], string> successCallback, bool isThumb)
        {
            string path = "";

            if (!TryGetPic(id, isThumb, out path))
            {
                Firebase.Storage.StorageReference picRef = storage_ref.Child
                                                               ("Pictures/" + (isThumb ? "thumb_" + id + ".png" : id + ".png"));

                string local_url = GetFilePath(id, isThumb);

                picRef.GetFileAsync(local_url).ContinueWith(task =>
                {
                    if (!task.IsFaulted && !task.IsCanceled)
                    {
                        byte[] file = ReadImageFromLocal(path);
                        successCallback(file, id);
                    }
                    else
                    {
                        successCallback(null, id);
                    }
                });
            }
            else
            {
                byte[] file = ReadImageFromLocal(path);
                successCallback(file, id);
            }
        }
Exemplo n.º 3
0
        // Utility function to download replay record from a given path and deserialize into
        // ReplayData struct
        public static Task <ReplayData> DownloadReplayRecordAsync(string replayPath)
        {
            TaskCompletionSource <ReplayData> tComplete = new TaskCompletionSource <ReplayData>();

            Firebase.Storage.StorageReference storageRef =
                Firebase.Storage.FirebaseStorage.DefaultInstance.GetReference(replayPath);

            storageRef.GetStreamAsync(stream => {
                tComplete.SetResult(ReplayData.CreateFromStream(stream));
            }).ContinueWith(task => {
                if (task.IsFaulted)
                {
                    tComplete.SetException(task.Exception);
                }
                if (task.IsCanceled)
                {
                    tComplete.SetCanceled();
                }
            });

            return(tComplete.Task);
        }