private async Task UploadPhotoAsync(ClubDTO Club) { var oldImageName = (await _repoWrapper.Club.GetFirstOrDefaultAsync(i => i.ID == Club.ID))?.Logo; var logoBase64 = Club.Logo; if (!string.IsNullOrWhiteSpace(logoBase64) && logoBase64.Length > 0) { var logoBase64Parts = logoBase64.Split(','); var extension = logoBase64Parts[0].Split(new[] { '/', ';' }, 3)[1]; if (!string.IsNullOrEmpty(extension)) { extension = (extension[0] == '.' ? "" : ".") + extension; } var fileName = Guid.NewGuid() + extension; await _ClubBlobStorage.UploadBlobForBase64Async(logoBase64Parts[1], fileName); Club.Logo = fileName; } if (!string.IsNullOrEmpty(oldImageName)) { await _ClubBlobStorage.DeleteBlobAsync(oldImageName); } }
private async Task <string> UploadPhotoAsyncFromBase64(int clubId, string imageBase64) { var oldImageName = (await _repoWrapper.Club.GetFirstOrDefaultAsync(x => x.ID == clubId)).Logo; if (string.IsNullOrWhiteSpace(imageBase64) || imageBase64.Length <= 0) { return(oldImageName); } var base64Parts = imageBase64.Split(','); var ext = base64Parts[0].Split(new[] { '/', ';' }, 3)[1]; var fileName = Guid.NewGuid() + "." + ext; await _clubBlobStorage.UploadBlobForBase64Async(base64Parts[1], fileName); if (!string.IsNullOrEmpty(oldImageName) && !string.Equals(oldImageName, "default_club_image.png") && oldImageName.Length < 30) { await _clubBlobStorage.DeleteBlobAsync(oldImageName); } return(fileName); }