apolloconfig/apollo · error · BadRequestException

file name [{originalFilename}] not valid

Error message

file name [{originalFilename}] not valid

What it means

Thrown by ConfigFileUtils.checkThreePart() when the filename split by the '+' character does not yield exactly 3 parts. Apollo's import filename convention is appId+clusterName+namespace.ext (e.g., '666+default+application.properties'). This check is called from getAppId(), getClusterName(), and getNamespace(). BadRequestException → HTTP 400.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java:86

    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);
    if (3 != parts.length) {
      throw new BadRequestException("file name [" + originalFilename + "] not valid");
    }
  }

  /**
   * <pre>
   *  "application+default+application.properties" -> "properties"
   *  "application+default+application.yml" -> "yml"
   * </pre>
   * @throws BadRequestException if file's format is invalid
   */
  public static String getFormat(final String originalFilename) {
    final List<String> fileNameSplit = Splitter.on(".").splitToList(originalFilename);
    if (fileNameSplit.size() <= 1) {
      throw new BadRequestException("The file format is invalid.");
    }
    return fileNameSplit.get(fileNameSplit.size() - 1);
  }

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Rename the file to the format: appId+clusterName+namespace.ext (e.g., '666+default+application.properties').
  2. Use ConfigFileUtils.toFilename(appId, clusterName, namespace, configFileFormat) to generate a correct filename programmatically.
  3. Ensure exactly two '+' separators in the filename.

Example fix

// before — filename 'application.properties'
// after — filename '666+default+application.properties'
Defensive patterns

Strategy: validation

Validate before calling

String filename = file.getOriginalFilename();
if (filename == null || filename.split("\\+").length != 3) {
    return ResponseEntity.badRequest().body("Filename must be: appId+clusterName+namespace.ext");
}

Type guard

static boolean hasThreePlusParts(String filename) {
    return filename != null && filename.split("\\+").length == 3;
}

Try / catch

try {
    ConfigFileUtils.getNamespace(file.getOriginalFilename());
} catch (BadRequestException e) {
    if (e.getMessage().contains("not valid")) {
        return ResponseEntity.badRequest().body("Expected format: appId+clusterName+namespace.ext");
    }
    throw e;
}

Prevention

When it happens

Trigger: Uploading a config file whose name doesn't follow the appId+cluster+namespace.format pattern. For example: 'application.properties' (1 part), '666+application.properties' (2 parts), or 'a+b+c+d.properties' (4+ parts after splitting on '+').

Common situations: File not renamed to Apollo's import convention before upload. User expects the import wizard to infer appId/cluster from context but the pipeline requires them in the filename. Consecutive or missing '+' separators produce wrong part counts.

Related errors


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