iflytek/astron-agent · warning · BusinessException
RESPONSE_FAILED
RESPONSE_FAILED
Error message
Empty file
What it means
ImageService.upload validates the incoming MultipartFile before doing any storage work and throws 'Empty file' when the file is null or isEmpty(). This is a deliberate input-validation failure — nothing reached S3/MinIO.
Solutions
- Fix the client to actually attach a non-empty file to the multipart request (correct part name).
- Validate file presence/size on the client side before submitting the form.
- In the controller, reject the request with 400 and a clear message when the file part is missing rather than reaching the service.
- If empty files should be tolerated, decide on a policy and handle them before calling upload().
Example fix
// before (caller)
service.upload(file); // file may be null/empty
// after (caller)
if (file == null || file.isEmpty()) {
throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Please select an image to upload");
}
service.upload(file); Defensive patterns
Strategy: validation
Validate before calling
if (file == null || file.isEmpty()) {
throw new IllegalArgumentException("Please attach a non-empty image file");
}
imageService.upload(file); Type guard
static boolean isUploadable(MultipartFile f) {
return f != null && !f.isEmpty();
} Try / catch
try {
String key = imageService.upload(file);
} catch (BusinessException e) {
if ("Empty file".equals(e.getMessage())) {
// return 400 Bad Request to the client
}
throw e;
} Prevention
- Enforce required file parts at the controller layer (@RequestParam MultipartFile file with validation).
- Validate file presence and size client-side before submitting the form.
- Return 400 with a clear message when the multipart part is missing.
When it happens
Trigger: Calling upload(null) or passing a MultipartFile with zero bytes — e.g. an image-upload endpoint hit with a missing file part, a form field posted without selecting a file, or a client sending Content-Length: 0.
Common situations: Frontend upload form submitting without a file selected; API consumers posting multipart requests where the file part name does not match what the controller binds; proxies stripping empty parts.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/385c5b7e698b9b1e.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/common/ImageService.java:41
// Allowed Content-Types (extend as needed)
private static final String[] ALLOWED_TYPES = {
"image/png", "image/jpeg", "image/jpg", "image/gif", "image/webp", "image/svg+xml"
};
// Recommended minimal part size for MinIO/Amazon multipart upload: 5MB
private static final long MULTIPART_PART_SIZE = 5L * 1024 * 1024;
/**
* Upload an image and return an accessible URL (if the bucket policy is not public, consider
* returning the object key or a pre-signed URL instead).
*
* @param file multipart file to upload; must not be {@code null} or empty
* @return the object key (or URL depending on bucket policy) of the uploaded image
* @throws BusinessException if validation fails, upload fails, or an I/O error occurs
*/
public String upload(MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Empty file");
}
final String contentType = normalizeContentType(file.getContentType());
if (!isAllowedType(contentType)) {
throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Unsupported content type: " + contentType);
}
final long size = file.getSize();
final String original = file.getOriginalFilename();
final String safeName = buildSafeFileName(original, contentType);
final String objectKey = "icon/user/" + safeName;
try (InputStream in = file.getInputStream()) {
if (size > 0) {
// Known content length: prefer direct upload
s3UtilClient.putObject(objectKey, in, size, contentType);
} else {View on GitHub (pinned to 5e758547a8)