{"record":{"id":"102dd44c21608592","repo":"apolloconfig/apollo","slug":"the-content-of-the-file-to-be-imported-is-incorrec","errorCode":null,"errorMessage":"The content of the file to be imported is incorrect.","messagePattern":"The content of the file to be imported is incorrect\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java","lineNumber":202,"sourceCode":"      }\n\n      // file.path format :\n      // ${appId}/${env}/${appId}+${cluster}+${namespaceName}\n      String filePath = entry.getName();\n      String content = readContent(dataZip);\n      if (content == null) {\n        throw new BadRequestException(\"Failed to read file content.\");\n      }\n      String[] info = filePath.replace('\\\\', '/').split(\"/\");\n      if (info.length != 3) {\n        throw new BadRequestException(\"Invalid file path in ZIP.\");\n      }\n      String fileName = info[2];\n      String fileNamePrefix = String.format(\"%s+%s+\", appId, clusterName);\n\n      if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())\n          || !fileName.startsWith(fileNamePrefix)) {\n        throw new BadRequestException(\"The content of the file to be imported is incorrect.\");\n      }\n      if (!fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) {\n        toImportNSs.add(new ImportNamespaceData(env, fileName, content, ignoreConflictNamespace));\n      }\n    }\n\n    if (CollectionUtils.isEmpty(toImportNSs)) {\n      throw new BadRequestException(\"The configuration to be imported is empty.\");\n    }\n\n    try {\n      LOGGER.info(\"Import namespace. namespace = {}\", toImportNSs.size());\n      doImport(Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(),\n          Lists.newArrayList(), toImportNSs, operator);\n    } catch (Exception e) {\n      LOGGER.error(\"import app config error.\", e);\n      throw new ServiceException(\"import app config error.\", e);\n    }","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java#L184-L220","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify all zip entries match the target app/env/cluster before import\nString expectedPrefix = appId + \"+\" + clusterName + \"+\";\ntry (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {\n  ZipEntry entry;\n  while ((entry = zis.getNextEntry()) != null) {\n    if (entry.isDirectory()) continue;\n    String[] info = entry.getName().replace('\\\\', '/').split(\"/\");\n    if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())\n        || !info[2].startsWith(expectedPrefix)) {\n      throw new IllegalArgumentException(\n        \"Zip entry does not match import target: \" + entry.getName());\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["apollo-portal","config-import","zip","bad-request","mismatch"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}