{"record":{"id":"53a6f4555ed2dfa8","repo":"apolloconfig/apollo","slug":"originalfilename-format-is-invalid","errorCode":null,"errorMessage":"{originalFilename} format is invalid!","messagePattern":"(.+?) format is invalid!","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java","lineNumber":144,"sourceCode":"   *  \"application+default+application.yml\" -> \"application.yml\"\n   *  \"application+default+application.json\" -> \"application.json\"\n   *  \"application+default+application.333.yml\" -> \"application.333.yml\"\n   * </pre>\n   * @throws BadRequestException if file's name is invalid\n   */\n  public static String getNamespace(final String originalFilename) {\n    checkThreePart(originalFilename);\n    final String[] threeParts = getThreePart(originalFilename);\n    final String suffix = threeParts[2];\n    if (!suffix.contains(\".\")) {\n      throw new BadRequestException(originalFilename + \" namespace and format is invalid!\");\n    }\n    final int lastDotIndex = suffix.lastIndexOf(\".\");\n    final String namespace = suffix.substring(0, lastDotIndex);\n    // format after last character '.'\n    final String format = suffix.substring(lastDotIndex + 1);\n    if (!ConfigFileFormat.isValidFormat(format)) {\n      throw new BadRequestException(originalFilename + \" format is invalid!\");\n    }\n    ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(format);\n    if (configFileFormat.equals(ConfigFileFormat.Properties)) {\n      return namespace;\n    } else {\n      // compatibility of other format\n      return namespace + \".\" + format;\n    }\n  }\n\n  /**\n   * <pre>\n   *   appId    cluster   namespace       return\n   *   666      default   application     666+default+application.properties\n   *   123      none      action.yml      123+none+action.yml\n   * </pre>\n   */\n  public static String toFilename(final String appId, final String clusterName,","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java#L126-L162","documentation":"Thrown by ConfigFileUtils.getNamespace() at line 144 when the format extracted from the filename's suffix (the substring after the last '.') is not a valid ConfigFileFormat. The format string is checked via ConfigFileFormat.isValidFormat(). For example, '666+default+application.txt' — 'txt' is not a supported Apollo config format. Supported formats include: properties, yml, yaml, json, xml, txt (as a namespace suffix), and others per ConfigFileFormat enum. BadRequestException → HTTP 400.","triggerScenarios":"Uploading a config file whose extension doesn't correspond to a valid Apollo ConfigFileFormat. For example, '.csv', '.ini', '.conf', or '.log'. The suffix is split at the last dot and the format portion is passed to ConfigFileFormat.isValidFormat(), which rejects unknown formats.","commonSituations":"User uploads a file with an unsupported extension. File has a double extension like '.config.yml' where the last segment happens to be invalid (though 'yml' would be valid). Apollo version doesn't support a newer format the user is trying to import.","solutions":["Use a supported Apollo config file extension: properties, yml, yaml, json, xml, or other formats recognized by ConfigFileFormat.","Check ConfigFileFormat.isValidFormat(extension) before importing.","Convert the file to a supported format before upload."],"exampleFix":"// before — filename '666+default+application.csv'\n// after — filename '666+default+application.properties'","handlingStrategy":"validation","validationCode":"String filename = file.getOriginalFilename();\nif (filename != null) {\n    String suffix = filename.split(\"\\\\+\")[2];\n    String format = suffix.substring(suffix.lastIndexOf('.') + 1);\n    if (!ConfigFileFormat.isValidFormat(format)) {\n        return ResponseEntity.badRequest().body(\"Unsupported format: \" + format);\n    }\n}","typeGuard":"static boolean hasValidConfigFormat(String filename) {\n    if (filename == null) return false;\n    String[] parts = filename.split(\"\\\\+\");\n    if (parts.length != 3 || !parts[2].contains(\".\")) return false;\n    String format = parts[2].substring(parts[2].lastIndexOf('.') + 1);\n    return ConfigFileFormat.isValidFormat(format);\n}","tryCatchPattern":"try {\n    String namespace = ConfigFileUtils.getNamespace(filename);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"format is invalid\")) {\n        return ResponseEntity.badRequest().body(\"Use a supported format extension (properties, yml, yaml, json, xml)\");\n    }\n    throw e;\n}","preventionTips":["Use only Apollo-supported config file extensions: properties, yml, yaml, json, xml.","Check ConfigFileFormat.isValidFormat(extension) before importing."],"tags":["apollo-portal","config-import","validation","config-format","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}