apolloconfig/apollo · error · BadRequestException
The file is empty. {originalFilename}
Error message
The file is empty. {originalFilename} What it means
Thrown by ConfigFileUtils.checkEmpty() when MultipartFile.isEmpty() returns true. Called from check() which is the entry point for config file import validation. The original filename is appended to the message for diagnostics. BadRequestException → HTTP 400. This fires before format and three-part checks.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java:56
*/
public class ConfigFileUtils {
public static final String APP_METADATA_FILENAME = "app.metadata";
public static final String CLUSTER_METADATA_FILE_SUFFIX = ".cluster.metadata";
public static final String APP_NAMESPACE_METADATA_FILE_SUFFIX = ".appnamespace.metadata";
public static void check(MultipartFile file) {
checkEmpty(file);
final String originalFilename = file.getOriginalFilename();
checkFormat(originalFilename);
}
/**
* @throws BadRequestException if file is empty
*/
static void checkEmpty(MultipartFile file) {
if (file.isEmpty()) {
throw new BadRequestException("The file is empty. " + file.getOriginalFilename());
}
}
/**
* @throws BadRequestException if file's format is invalid
*/
static void checkFormat(final String originalFilename) {
final List<String> fileNameSplit = Splitter.on(".").splitToList(originalFilename);
if (fileNameSplit.size() <= 1) {
throw new BadRequestException("The file format is invalid.");
}
for (String s : fileNameSplit) {
if (StringUtils.isEmpty(s)) {
throw new BadRequestException("The file format is invalid.");
}
}
}View on GitHub (pinned to d95fc18d11)
Solutions
- Ensure the uploaded file has content before submitting.
- Add client-side validation to check file.size > 0 before upload.
- If importing programmatically, verify the file is non-empty before attaching to the multipart request.
Example fix
// before — uploading a zero-byte file
// after — client-side check
if (file.size === 0) { alert('File is empty'); return; } Defensive patterns
Strategy: validation
Validate before calling
if (file == null || file.isEmpty()) {
return ResponseEntity.badRequest().body("File is empty or missing");
}
ConfigFileUtils.check(file); Type guard
static boolean isNonEmptyFile(MultipartFile file) {
return file != null && !file.isEmpty();
} Try / catch
try {
ConfigFileUtils.check(file);
} catch (BadRequestException e) {
if (e.getMessage().contains("file is empty")) {
return ResponseEntity.badRequest().body("Upload a non-empty file");
}
throw e;
} Prevention
- Validate file.getSize() > 0 on the client before upload.
- Check file existence and content before attaching to the multipart request.
When it happens
Trigger: Uploading a config file via the import endpoint (ConfigsImportController) where the MultipartFile has no content — zero bytes, or the client sent an empty file body. For example, selecting a file in the UI that was truncated to zero bytes, or an API POST with an empty multipart body.
Common situations: Client uploads a file that was deleted or truncated between selection and submission. Network issue results in an empty body. Test script creates a temporary file but writes nothing. File picker on some OS allows selecting a 0-byte file.
Related errors
- The file format is invalid.
- file name [{originalFilename}] not valid
- The app does not exist in the specified environment and clus
- {originalFilename} namespace and format is invalid!
- {originalFilename} format is invalid!
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/e5e9ff540fc4cef9.
Report an issue: GitHub.