elunez/eladmin · error · BadRequestException
文件超出规定大小:{maxSize}MB
Error message
文件超出规定大小:{maxSize}MB What it means
FileUtil.checkSize throws BadRequestException when an uploaded file's byte size exceeds maxSize MB (maxSize * 1024 * 1024). It is a pre-upload guard used by local-storage and upload services to reject oversized files before they are written. The message interpolates the configured maxSize so the client knows the ceiling.
Source
Thrown at eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java:291
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
if (image.contains(type)) {
return IMAGE;
} else if (documents.contains(type)) {
return TXT;
} else if (music.contains(type)) {
return MUSIC;
} else if (video.contains(type)) {
return VIDEO;
} else {
return OTHER;
}
}
public static void checkSize(long maxSize, long size) {
// 1M
int len = 1024 * 1024;
if (size > (maxSize * len)) {
throw new BadRequestException("文件超出规定大小:" + maxSize + "MB");
}
}
/**
* 判断两个文件是否相同
*/
public static boolean check(File file1, File file2) {
String img1Md5 = getMd5(file1);
String img2Md5 = getMd5(file2);
if(img1Md5 != null){
return img1Md5.equals(img2Md5);
}
return false;
}
/**
* 判断两个文件是否相同
*/View on GitHub (pinned to 55fbf70595)
Solutions
- Increase the configured max size in eladmin.yml (e.g. spring.servlet.max-size: 50) and restart, if large uploads are intended.
- On the client, check file.size against the limit before uploading and show a friendly message.
- Keep nginx client_max_body_size >= the application limit so requests are rejected consistently by the app, not truncated by the proxy.
- Compress or split the file (images: convert to WebP/JPEG with lower quality) to fit under the limit.
Example fix
// before: upload rejected for a 30MB file with maxSize=5
FileUtil.checkSize(maxSize, file.getSize());
// after: raise the limit in eladmin.yml
# spring:
# servlet:
# max-size: 50 # MB
// or guard client-side
// if (file.size > maxSizeMB * 1024 * 1024) alert('文件超出 ' + maxSizeMB + 'MB'); Defensive patterns
Strategy: validation
Validate before calling
// Client: validate before upload
const MAX_MB = 5; // must mirror spring.servlet.max-size
if (file.size > MAX_MB * 1024 * 1024) {
alert(`文件超出规定大小:${MAX_MB}MB`);
return;
}
upload(file); Type guard
function isWithinSize(file, maxMb) {
return typeof file.size === 'number' && file.size <= maxMb * 1024 * 1024;
} Try / catch
try {
storageService.add(name, file); // internally calls FileUtil.checkSize
} catch (BadRequestException e) {
if (e.getMessage().startsWith("文件超出规定大小")) return showFriendlySizeError(file);
throw e;
} Prevention
- Surface the configured maxSize in the UI so users know the ceiling before choosing a file.
- Compress images/videos client-side before upload.
- Keep nginx client_max_body_size >= the Spring limit to avoid proxy-level truncation.
- Never disable the check for 'big files' — raise the configured limit instead.
When it happens
Trigger: Uploading a file larger than the maxSize passed by the caller, e.g. LocalStorageService.add(...) calling FileUtil.checkSize(properties.getMaxSize(), file.getSize()) when spring.servlet.max-size (in MB) is smaller than the file; avatar or document uploads above the configured limit.
Common situations: Default maxSize (often 5MB in eladmin.yml) too small for user uploads; nginx client_max_body_size larger than the app limit so the request reaches Spring and then fails; clients not validating file size before POST; unit confusion (maxSize is in MB, size in bytes).
Related errors
- 文件格式错误!, 仅支持 gif jpg png jpeg 格式
- {entity} 不存在: {parameter} is {value}
- 没有这个选项
- Database not exist
- 非法的应用名称,请勿包含[; | &]等特殊字符
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/17a1fb65df880fa2.
Report an issue: GitHub.