{"record":{"id":"b5a89416088a393d","repo":"apolloconfig/apollo","slug":"file-name-originalfilename-not-valid","errorCode":null,"errorMessage":"file name [{originalFilename}] not valid","messagePattern":"file name \\[(.+?)\\] not valid","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java","lineNumber":86,"sourceCode":"\n    for (String s : fileNameSplit) {\n      if (StringUtils.isEmpty(s)) {\n        throw new BadRequestException(\"The file format is invalid.\");\n      }\n    }\n  }\n\n  static String[] getThreePart(final String originalFilename) {\n    return originalFilename.split(\"[+]\");\n  }\n\n  /**\n   * @throws BadRequestException if file's name cannot divide to 3 parts by \"+\" symbol\n   */\n  static void checkThreePart(final String originalFilename) {\n    String[] parts = getThreePart(originalFilename);\n    if (3 != parts.length) {\n      throw new BadRequestException(\"file name [\" + originalFilename + \"] not valid\");\n    }\n  }\n\n  /**\n   * <pre>\n   *  \"application+default+application.properties\" -> \"properties\"\n   *  \"application+default+application.yml\" -> \"yml\"\n   * </pre>\n   * @throws BadRequestException if file's format is invalid\n   */\n  public static String getFormat(final String originalFilename) {\n    final List<String> fileNameSplit = Splitter.on(\".\").splitToList(originalFilename);\n    if (fileNameSplit.size() <= 1) {\n      throw new BadRequestException(\"The file format is invalid.\");\n    }\n    return fileNameSplit.get(fileNameSplit.size() - 1);\n  }\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java#L68-L104","documentation":"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.","triggerScenarios":"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 '+').","commonSituations":"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.","solutions":["Rename the file to the format: appId+clusterName+namespace.ext (e.g., '666+default+application.properties').","Use ConfigFileUtils.toFilename(appId, clusterName, namespace, configFileFormat) to generate a correct filename programmatically.","Ensure exactly two '+' separators in the filename."],"exampleFix":"// before — filename 'application.properties'\n// after — filename '666+default+application.properties'","handlingStrategy":"validation","validationCode":"String filename = file.getOriginalFilename();\nif (filename == null || filename.split(\"\\\\+\").length != 3) {\n    return ResponseEntity.badRequest().body(\"Filename must be: appId+clusterName+namespace.ext\");\n}","typeGuard":"static boolean hasThreePlusParts(String filename) {\n    return filename != null && filename.split(\"\\\\+\").length == 3;\n}","tryCatchPattern":"try {\n    ConfigFileUtils.getNamespace(file.getOriginalFilename());\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"not valid\")) {\n        return ResponseEntity.badRequest().body(\"Expected format: appId+clusterName+namespace.ext\");\n    }\n    throw e;\n}","preventionTips":["Follow the appId+clusterName+namespace.ext naming convention for import files.","Use ConfigFileUtils.toFilename() to construct valid filenames."],"tags":["apollo-portal","config-import","file-upload","validation","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}