public async Task UploadAsync(long groupId) { var profilePictureFile = _contextAccessor.HttpContext.Request.Form.Files.First(); //Check input if (profilePictureFile == null) { throw new UserFriendlyException(L("ProfilePicture_Change_Error")); } if (profilePictureFile.Length > 1048576) //1MB. { throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit")); } byte[] fileBytes; using (var stream = profilePictureFile.OpenReadStream()) { fileBytes = stream.GetAllBytes(); } if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif)) { throw new Exception("Uploaded file is not an accepted image file !"); } await _pictureManager.UploadPictureAsync(fileBytes, profilePictureFile.FileName, groupId); }