public Task PutBytesAsync(byte[] bytes, MetadataChange?metadata = null, IProgress <IUploadState>?progress = null, CancellationToken cancellationToken = default, PauseToken pauseToken = default)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException(nameof(bytes));
            }

            var data = NSData.FromArray(bytes);
            var tcs  = new TaskCompletionSource <bool>();

            var uploadTask = _storageReference.PutData(data, metadata?.ToStorageMetadata(), (storageMetadata, error) =>
            {
                if (error != null)
                {
                    tcs.SetException(ExceptionMapper.Map(new NSErrorException(error)));
                }
                else
                {
                    tcs.SetResult(true);
                }
            });

            if (progress != null)
            {
                uploadTask.ObserveStatus(StorageTaskStatus.Progress, snapshot => progress.Report(new StorageTaskSnapshotWrapper(snapshot)));
            }

            if (cancellationToken != default)
            {
                cancellationToken.Register(uploadTask.Cancel);
            }

            if (pauseToken != default)
            {
                pauseToken.SetStorageTask(new StorageUploadTaskWrapper(uploadTask));
            }

            return(tcs.Task);
        }
        public Task PutFileAsync(string filePath, MetadataChange metadata = null, IProgress <IUploadState> progress = null, CancellationToken cancellationToken = default(CancellationToken), PauseToken pauseToken = default(PauseToken))
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            var tcs = new TaskCompletionSource <bool>();

            var uploadTask = _storageReference.PutFile(NSUrl.FromFilename(filePath), metadata?.ToStorageMetadata(), (storageMetadata, error) =>
            {
                if (error != null)
                {
                    tcs.SetException(ExceptionMapper.Map(new NSErrorException(error)));
                }
                else
                {
                    tcs.SetResult(true);
                }
            });

            if (progress != null)
            {
                uploadTask.ObserveStatus(StorageTaskStatus.Progress, snapshot => progress.Report(new StorageTaskSnapshotWrapper(snapshot)));
            }

            if (cancellationToken != default(CancellationToken))
            {
                cancellationToken.Register(uploadTask.Cancel);
            }

            if (pauseToken != default(PauseToken))
            {
                pauseToken.SetStorageTask(new StorageUploadTaskWrapper(uploadTask));
            }

            return(tcs.Task);
        }
        private Task Upload(UploadTask uploadTask, IProgress <IUploadState>?progress = null, CancellationToken cancellationToken = default, PauseToken pauseToken = default)
        {
            var tcs = new TaskCompletionSource <bool>();

            uploadTask.AddOnCompleteListener(new OnCompleteHandlerListener(task =>
            {
                if (task.IsSuccessful)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(ExceptionMapper.Map(task.Exception));
                }
            }));

            if (progress != null)
            {
                uploadTask.AddOnProgressListener(new OnProgressHandlerListener(snapshot =>
                {
                    var uploadTaskSnapshot = snapshot.JavaCast <UploadTask.TaskSnapshot>();
                    progress.Report(new UploadTaskSnapshotWrapper(uploadTaskSnapshot !));
                }));
            }

            if (cancellationToken != default)
            {
                cancellationToken.Register(() => uploadTask.Cancel());
            }

            if (pauseToken != default)
            {
                pauseToken.SetStorageTask(new StorageTaskWrapper(uploadTask));
            }

            return(tcs.Task);
        }