{"record":{"id":"8c2d984d13e5fc32","repo":"apolloconfig/apollo","slug":"the-file-format-is-invalid","errorCode":null,"errorMessage":"The file format is invalid.","messagePattern":"The file 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":66,"sourceCode":"    checkFormat(originalFilename);\n  }\n\n  /**\n   * @throws BadRequestException if file is empty\n   */\n  static void checkEmpty(MultipartFile file) {\n    if (file.isEmpty()) {\n      throw new BadRequestException(\"The file is empty. \" + file.getOriginalFilename());\n    }\n  }\n\n  /**\n   * @throws BadRequestException if file's format is invalid\n   */\n  static void checkFormat(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\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);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java#L48-L84","documentation":"Thrown by ConfigFileUtils.checkFormat() at line 66 when the filename split by '.' yields only one part (fileNameSplit.size() <= 1), meaning the filename has no extension. Called from check() during import validation. For example, a filename like 'application' with no dot triggers this. BadRequestException → HTTP 400.","triggerScenarios":"Uploading a config file whose original filename has no '.' separator — e.g., 'configfile', 'application', or any name without an extension. The import pipeline (check → checkFormat) requires at least a dot-delimited extension to determine the config format.","commonSituations":"File was renamed without an extension. OS hides known extensions and the user selects a file whose actual name lacks one. Programmatic upload where the filename was constructed without appending a format suffix.","solutions":["Rename the file to include a valid extension (e.g., 'application.properties', 'config.yml').","Ensure the multipart filename (Content-Disposition filename) includes the extension.","When generating filenames programmatically, append the format suffix."],"exampleFix":"// before — filename 'configfile' (no extension)\n// after — filename 'configfile.properties'","handlingStrategy":"validation","validationCode":"String filename = file.getOriginalFilename();\nif (filename == null || !filename.contains(\".\")) {\n    return ResponseEntity.badRequest().body(\"Filename must include a format extension (e.g., .properties)\");\n}","typeGuard":"static boolean hasFileExtension(String filename) {\n    return filename != null && filename.contains(\".\");\n}","tryCatchPattern":"try {\n    ConfigFileUtils.check(file);\n} catch (BadRequestException e) {\n    if (e.getMessage().equals(\"The file format is invalid.\") && file.getOriginalFilename() != null\n            && !file.getOriginalFilename().contains(\".\")) {\n        return ResponseEntity.badRequest().body(\"Filename needs an extension (e.g., .properties, .yml)\");\n    }\n    throw e;\n}","preventionTips":["Ensure the uploaded filename includes a dot-separated extension.","Use toFilename() to generate correctly-named files for import."],"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"}