apolloconfig/apollo · error · BadRequestException
The file format is invalid.
Error message
The file format is invalid.
What it means
Thrown by ConfigFileUtils.checkFormat() at line 66 when the filename split by '.' yields only one part (fileNameSplit.size() <= 1), meaning the filename has no extension. Called from check() during import validation. For example, a filename like 'application' with no dot triggers this. BadRequestException → HTTP 400.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java:66
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.");
}
}
}
static String[] getThreePart(final String originalFilename) {
return originalFilename.split("[+]");
}
/**
* @throws BadRequestException if file's name cannot divide to 3 parts by "+" symbol
*/
static void checkThreePart(final String originalFilename) {
String[] parts = getThreePart(originalFilename);View on GitHub (pinned to d95fc18d11)
Solutions
- Rename the file to include a valid extension (e.g., 'application.properties', 'config.yml').
- Ensure the multipart filename (Content-Disposition filename) includes the extension.
- When generating filenames programmatically, append the format suffix.
Example fix
// before — filename 'configfile' (no extension) // after — filename 'configfile.properties'
Defensive patterns
Strategy: validation
Validate before calling
String filename = file.getOriginalFilename();
if (filename == null || !filename.contains(".")) {
return ResponseEntity.badRequest().body("Filename must include a format extension (e.g., .properties)");
} Type guard
static boolean hasFileExtension(String filename) {
return filename != null && filename.contains(".");
} Try / catch
try {
ConfigFileUtils.check(file);
} catch (BadRequestException e) {
if (e.getMessage().equals("The file format is invalid.") && file.getOriginalFilename() != null
&& !file.getOriginalFilename().contains(".")) {
return ResponseEntity.badRequest().body("Filename needs an extension (e.g., .properties, .yml)");
}
throw e;
} Prevention
- Ensure the uploaded filename includes a dot-separated extension.
- Use toFilename() to generate correctly-named files for import.
When it happens
Trigger: Uploading a config file whose original filename has no '.' separator — e.g., 'configfile', 'application', or any name without an extension. The import pipeline (check → checkFormat) requires at least a dot-delimited extension to determine the config format.
Common situations: File was renamed without an extension. OS hides known extensions and the user selects a file whose actual name lacks one. Programmatic upload where the filename was constructed without appending a format suffix.
Related errors
- The file is empty. {originalFilename}
- 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/8c2d984d13e5fc32.
Report an issue: GitHub.