apolloconfig/apollo · error · BadRequestException
The content of the file to be imported is incorrect.
Error message
The content of the file to be imported is incorrect.
What it means
Thrown as a BadRequestException by ConfigsImportService.importAppConfigFromZipFile() when a zip entry's path segments don't match the import parameters. Specifically: info[0] must equal the appId, info[1] must case-insensitively equal the env name, and the filename must start with the appId+clusterName+ prefix. Any mismatch means the file content doesn't belong to the specified app/env/cluster.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java:202
}
// file.path format :
// ${appId}/${env}/${appId}+${cluster}+${namespaceName}
String filePath = entry.getName();
String content = readContent(dataZip);
if (content == null) {
throw new BadRequestException("Failed to read file content.");
}
String[] info = filePath.replace('\\', '/').split("/");
if (info.length != 3) {
throw new BadRequestException("Invalid file path in ZIP.");
}
String fileName = info[2];
String fileNamePrefix = String.format("%s+%s+", appId, clusterName);
if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())
|| !fileName.startsWith(fileNamePrefix)) {
throw new BadRequestException("The content of the file to be imported is incorrect.");
}
if (!fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) {
toImportNSs.add(new ImportNamespaceData(env, fileName, content, ignoreConflictNamespace));
}
}
if (CollectionUtils.isEmpty(toImportNSs)) {
throw new BadRequestException("The configuration to be imported is empty.");
}
try {
LOGGER.info("Import namespace. namespace = {}", toImportNSs.size());
doImport(Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),
Lists.newArrayList(), toImportNSs, operator);
} catch (Exception e) {
LOGGER.error("import app config error.", e);
throw new ServiceException("import app config error.", e);
}View on GitHub (pinned to d95fc18d11)
Solutions
- Verify the import request's appId, env, and clusterName match the zip's origin.
- Inspect the zip entry names (unzip -l) and confirm they all start with the correct appId/env/cluster prefix.
- Use the full-data import endpoint (importDataFromZipFile) if the zip contains multiple apps or environments.
- Re-export the configuration from the correct source app and environment.
Defensive patterns
Strategy: validation
Validate before calling
// Verify all zip entries match the target app/env/cluster before import
String expectedPrefix = appId + "+" + clusterName + "+";
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.isDirectory()) continue;
String[] info = entry.getName().replace('\\', '/').split("/");
if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())
|| !info[2].startsWith(expectedPrefix)) {
throw new IllegalArgumentException(
"Zip entry does not match import target: " + entry.getName());
}
}
} Prevention
- Confirm the zip was exported from the same appId/env/cluster being imported into.
- Double-check appId, env, and clusterName parameters in the import request.
- Use the full-data import endpoint if the zip contains multiple apps or environments.
When it happens
Trigger: Importing a zip into appId/env/clusterName where at least one entry belongs to a different app, environment, or cluster. For example, a zip exported from app 'A' being imported as app 'B', or entries from env 'DEV' imported into env 'PROD'.
Common situations: Wrong zip file selected for import; zip contains entries from multiple apps/environments; appId or clusterName parameter typo in the import request; zip from a different Apollo deployment.
Related errors
- Failed to read file content.
- Invalid file path in ZIP.
- The configuration to be imported is empty.
- import configs failed: %s
- import app configs failed: %s
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/102dd44c21608592.
Report an issue: GitHub.