Exemplo n.º 1
0
        private async Task TryUploadFacebookAvatarAsync(string userId, string externalUserId)
        {
            try
            {
                var avatarUrl = _facebookService.GetAvatarUrl(externalUserId);
                var avatar    = await _fileResolver.FromUrlAsync(avatarUrl);

                if (avatar.HasNoValue)
                {
                    return;
                }
                var file = Common.Files.File.Empty;
                using (var stream = new MemoryStream())
                {
                    await avatar.Value.CopyToAsync(stream);

                    file = Common.Files.File.Create($"{userId}.jpg", "image/jpeg", stream.ToArray());
                }
                await _avatarService.AddOrUpdateAsync(userId, file);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"There was an error when trying to upload the avatar from Facebook for user: {externalUserId}.");
            }
        }