apolloconfig/apollo · error · BadRequestException

Invalid file path in ZIP.

Error message

Invalid file path in ZIP.

What it means

Thrown as a BadRequestException by ConfigsImportService.importAppConfigFromZipFile() when a zip entry's file path does not split into exactly 3 segments by '/'. The expected path format is ${appId}/${env}/${appId}+${cluster}+${namespaceName}. Paths with fewer or more segments indicate a structurally invalid zip for app-config import.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java:195

    }

    List<ImportNamespaceData> toImportNSs = Lists.newArrayList();
    ZipEntry entry;
    while ((entry = dataZip.getNextEntry()) != null) {
      if (entry.isDirectory()) {
        continue;
      }

      // 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 {

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Ensure the zip was generated by the single-app export endpoint (matching importAppConfigFromZipFile), not the full data export.
  2. Inspect the zip's entry paths (unzip -l) and confirm each non-directory entry matches ${appId}/${env}/${filename}.
  3. Re-export the specific app's configuration from the portal using the correct export function.
  4. Remove any extraneous directory entries or restructure paths to the expected 3-segment format.
Defensive patterns

Strategy: validation

Validate before calling

// Validate zip entry path format before import
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {
  ZipEntry entry;
  while ((entry = zis.getNextEntry()) != null) {
    if (entry.isDirectory()) continue;
    String[] segments = entry.getName().replace('\\', '/').split("/");
    if (segments.length != 3) {
      throw new IllegalArgumentException(
        "Invalid zip entry path (expected 3 segments): " + entry.getName());
    }
  }
}

Prevention

When it happens

Trigger: Importing a zip via importAppConfigFromZipFile that contains entries whose paths don't conform to the 3-segment appId/env/filename format. This includes entries at the root, nested subdirectories, or paths with extra slashes.

Common situations: Using a full-export zip (from importDataFromZipFile format which has 4+ segments) with the single-app import endpoint; zip created by an older/newer Apollo version with a different path layout; manually edited zip with extra directories.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/b18d7fa844410085. Report an issue: GitHub.