{"record":{"id":"f4b4132daaae8e27","repo":"kestra-io/kestra","slug":"cannot-import-file-of-type-type","errorCode":null,"errorMessage":"Cannot import file of type <type>","messagePattern":"Cannot import file of type <type>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/models/HasSource.java","lineNumber":92,"sourceCode":"                for (int i = 0; i < sources.size(); i++) {\n                    String source = sources.get(i);\n                    reader.accept(source, fileName + \"(flow number: \" + i + \")\");\n                }\n            } else if (fileName.endsWith(\".zip\")) {\n\n                try (ZipInputStream archive = ProtectedZipInputStream.of(inputStream, zipBombProtection)) {\n                    ZipEntry entry;\n                    while ((entry = archive.getNextEntry()) != null) {\n                        if (entry.isDirectory() || !isYAML(entry.getName())) {\n                            continue;\n                        }\n                        reader.accept(new String(archive.readAllBytes()), entry.getName());\n                    }\n                }\n            } else {\n                int extensionIndex = fileName.lastIndexOf('.');\n                String type = extensionIndex >= 0 ? fileName.substring(extensionIndex) : fileName;\n                throw new IllegalArgumentException(\"Cannot import file of type \" + type);\n            }\n        }\n    }\n\n    private static boolean isYAML(final String fileName) {\n        return fileName.endsWith(\".yaml\") || fileName.endsWith(\".yml\");\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":101,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/models/HasSource.java#L74-L101","documentation":"Thrown by HasSource.readSourceFile() when the uploaded file is neither a .yaml/.yml file nor a .zip archive. The import endpoint only accepts YAML flow files or ZIP archives of YAML files; any other extension (or no extension) is rejected with the offending type extracted from the filename. This guards the flow import API at the trust boundary.","triggerScenarios":"Uploading a .json, .txt, .csv, or extensionless file to a flow import endpoint; uploading a .tar or .gz archive that is not a zip; a misconfigured client sending the wrong Content-Type or filename.","commonSituations":"User exports a flow as JSON and tries to import it; drag-and-drop of a non-YAML file in the UI; a CI script uploads the wrong artifact.","solutions":["Convert the file to YAML (.yaml or .yml) before importing.","If importing multiple files, bundle them into a .zip archive of YAML files.","Verify the uploaded filename has the correct extension and is not sanitized away by a proxy.","Check that the multipart upload preserves the original filename."],"exampleFix":"// before\nimport file: flow.json\n// IllegalArgumentException: Cannot import file of type .json\n\n// after\nimport file: flow.yaml   // or bundle into flows.zip","handlingStrategy":"validation","validationCode":"String name = fileUpload.getFilename().toLowerCase();\nboolean yaml = name.endsWith(\".yaml\") || name.endsWith(\".yml\");\nboolean zip = name.endsWith(\".zip\");\nif (!yaml && !zip) {\n    throw new IllegalArgumentException(\"Cannot import file of type \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n    HasSource.readSourceFile(protection, upload, reader);\n} catch (IllegalArgumentException e) {\n    return ResponseEntity.badRequest().body(Map.of(\"error\", e.getMessage()));\n}","preventionTips":["Validate the file extension on the client before upload.","Restrict the file picker accept attribute to .yaml,.yml,.zip."],"tags":["import","validation","yaml","file-upload"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}