async Task UploadImageIfAvailable(IConnectCollectionsApi api) { var image = ImageLarge ?? Image; if (image != null && Uri.IsWellFormedUriString(image, UriKind.Absolute)) { await UploadImage(image, api).ConfigureAwait(false); } }
async Task UploadImage(string image, IConnectCollectionsApi api) { try { // todo: move into the api or ? var tmpFile = Path.GetTempPath().ToAbsoluteDirectoryPath().GetChildFileWithName(Path.GetFileName(image)); await SyncEvilGlobal.FileDownloader.DownloadAsync(new FileDownloadSpec(new Uri(image), tmpFile)) .ConfigureAwait(false); await api.UploadCollectionAvatar(tmpFile, PublishedId.Value).ConfigureAwait(false); } catch (Exception ex) { throw new CollectionImageUploadException("A problem occurred trying to publish the image", ex); } }