nopSolutions/nopCommerce · warning · NopException
Account.Avatar.MaximumUploadedFileSize
Error message
Account.Avatar.MaximumUploadedFileSize
What it means
Thrown during customer avatar upload when the uploaded file's byte length exceeds _customerSettings.AvatarMaximumSizeBytes. The message is the localized 'Account.Avatar.MaximumUploadedFileSize' resource formatted with the configured max size.
Source
Thrown at src/Presentation/Nop.Web/Controllers/CustomerController.cs:2079
if (!_customerSettings.AllowCustomersToUploadAvatars)
return RedirectToRoute(NopRouteNames.General.CUSTOMER_INFO);
var contentType = uploadedFile?.ContentType.ToLowerInvariant();
if (contentType != null && !contentType.Equals("image/jpeg") && !contentType.Equals("image/gif"))
ModelState.AddModelError("", await _localizationService.GetResourceAsync("Account.Avatar.UploadRules"));
if (ModelState.IsValid)
{
try
{
var customerAvatar = await _pictureService.GetPictureByIdAsync(await _genericAttributeService.GetAttributeAsync<int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute));
if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
{
var avatarMaxSize = _customerSettings.AvatarMaximumSizeBytes;
if (uploadedFile.Length > avatarMaxSize)
throw new NopException(string.Format(await _localizationService.GetResourceAsync("Account.Avatar.MaximumUploadedFileSize"), avatarMaxSize));
var customerPictureBinary = await _downloadService.GetDownloadBitsAsync(uploadedFile);
if (customerAvatar != null)
customerAvatar = await _pictureService.UpdatePictureAsync(customerAvatar.Id, customerPictureBinary, contentType, null);
else
customerAvatar = await _pictureService.InsertPictureAsync(customerPictureBinary, contentType, null);
}
var customerAvatarId = 0;
if (customerAvatar != null)
customerAvatarId = customerAvatar.Id;
await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.AvatarPictureIdAttribute, customerAvatarId);
model.AvatarUrl = await _pictureService.GetPictureUrlAsync(
await _genericAttributeService.GetAttributeAsync<int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute),
_mediaSettings.AvatarPictureSize,
false);
View on GitHub (pinned to 64bdf2ff08)
Solutions
- Increase AvatarMaximumSizeBytes in Customer settings (Admin > Configuration > Settings > Customer settings > Avatar) to a practical limit (e.g. 200KB+).
- Instruct users to downscale/compress images before upload; add client-side size validation with a max-size check on the file input.
- Server-side, optionally resize the image automatically instead of rejecting it.
Example fix
// before
if (uploadedFile.Length > avatarMaxSize)
throw new NopException(string.Format(await _localizationService.GetResourceAsync("Account.Avatar.MaximumUploadedFileSize"), avatarMaxSize));
// after: add client-side pre-check
// <input type="file" accept="image/*" onchange="if(this.files[0].size > @avatarMaxSize){ alert('Too large'); this.value=''; }" /> Defensive patterns
Strategy: validation
Validate before calling
// Server-side pre-check before reading the stream
var avatarMaxSize = _customerSettings.AvatarMaximumSizeBytes;
if (uploadedFile != null && uploadedFile.Length > avatarMaxSize)
{
ModelState.AddModelError("", $"Max avatar size is {avatarMaxSize} bytes.");
return View(model);
} Try / catch
catch (NopException exc) when (exc.Message.Contains("MaximumUploadedFileSize"))
{
ModelState.AddModelError("", exc.Message);
return View(model);
} Prevention
- Add a client-side file-input size check (onchange) so users are warned before upload.
- Set AvatarMaximumSizeBytes to a realistic value for modern photos.
- Recommend users compress/resize images; consider server-side image resizing as an alternative.
When it happens
Trigger: Customer uploads an avatar image whose ContentLength/Length is greater than AvatarMaximumSizeBytes (default 20000 bytes / ~20KB) via the avatar upload action in CustomerController (line ~2079).
Common situations: User uploaded a high-resolution photo straight from a phone/camera (multi-MB); AvatarMaximumSizeBytes left at the very low default; the prior contentType/extension validation passed but the size did not.
Related errors
- Data provider supports connection only with login and passwo
- Data provider supports connection only with login and passwo
- {httpResponse.ReasonPhrase}
- Usernames are disabled
- Exchange ratio not set for dimension [{sourceMeasureDimensio
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/e569845ffc643551.
Report an issue: GitHub.