private void PublishImageToStorage(string localFile, string key)
    {
        // Create a reference to the file you want to upload
        StorageReference imageReference = storageFolderReference.Child($"{key}.jpg");

        // Upload the file to the itemPath
        imageReference.PutFileAsync(localFile)
        .ContinueWith((task) =>
        {
            // error uploading
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
            }

            // uploaded successfuly
            else
            {
                // Metadata contains file metadata such as size, content-type, and download URL.
                Firebase.Storage.StorageMetadata metadata = task.Result;
                imageReference.GetMetadataAsync().ContinueWith((task2) =>
                {
                    string downloadUrl = task2.ToString();

                    Debug.Log("Finished uploading...");
                    Debug.Log("download url = " + downloadUrl);
                });
            }
        });
    }
        public async Task <IStorageMetadata> GetMetadataAsync()
        {
            try
            {
                var metadata = await _storageReference.GetMetadataAsync().ConfigureAwait(false);

                return(new StorageMetadataWrapper(metadata));
            }
            catch (NSErrorException e)
            {
                throw ExceptionMapper.Map(e);
            }
        }
Exemplo n.º 3
0
    public void DownloadLatestMap(DownloadCallback callback)
    {
        reference.GetMetadataAsync().ContinueWith((Task <StorageMetadata> metadataTask) =>
        {
            if (metadataTask.IsFaulted || metadataTask.IsCanceled)
            {
                Debug.Log("Failed to download metadata.");
                Debug.Log(metadataTask.Exception.InnerException.Message);
            }
            else if (metadataTask.IsCompleted)
            {
                Debug.Log("Metadata successfully downloaded.");
                StorageMetadata meta = metadataTask.Result;

                // If there's no local map or local map is old, download new map from cloud.
                if (!MapExists || meta.CreationTimeMillis > File.GetLastWriteTimeUtc(WorldMapPath))
                {
                    Debug.Log("Beginning map download.");
                    DownloadInProgress = true;
                    reference.GetFileAsync(FirebaseWorldMapPath).ContinueWith(mapTask =>
                    {
                        DownloadInProgress = false;

                        if (mapTask.IsFaulted || mapTask.IsCanceled)
                        {
                            Debug.Log("Failed to download map.");
                            Debug.Log(mapTask.Exception.InnerException.Message);
                        }
                        else if (mapTask.IsCompleted)
                        {
                            Debug.Log("Map successfully downloaded.");
                            callback();
                        }
                    });
                }
                else
                {
                    Debug.Log("No need to download new map.");
                    callback();
                }
            }
        });
    }
Exemplo n.º 4
0
        /// <summary>
        /// Downlaod file form current storage location
        /// </summary>
        /// <param name="targetPath">current file path</param>
        /// <returns>file binary file</returns>
        public async Task <DownloadedFile> DownloadFileFromStorage(string targetPath, FirebaseUser user)
        {
            isDonwloaded = true;
            DownloadedFile current = new DownloadedFile();

            Storage_ref = Storage.GetReferenceFromUrl(targetPath);

            const long maxAllowedSize = 500 * 1024 * 1024; //max donwload file 500MB
            await Storage_ref.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) =>
            {
                if (task.IsFaulted || task.IsCanceled)
                {
                    Debug.Log(task.Exception.ToString());
                    // Uh-oh, an error occurred!
                    isDonwloaded = false;
                }
                else
                {
                    //save file to byte array
                    current.SetData(task.Result);
                    Debug.Log("Finished downloading!");
                }
            });

            await Storage_ref.GetMetadataAsync().ContinueWith((Task <StorageMetadata> task) =>
            {
                if (!task.IsFaulted && !task.IsCanceled)
                {
                    StorageMetadata meta = task.Result;
                    current.SetFileType(meta.ContentType);
                }
            });

            isDonwloaded = false;
            return(current);
        }
 public async Task <IStorageMetadata> GetMetadataAsync()
 {
     return((await _wrapped.GetMetadataAsync()).ToAbstract());
 }