kestra-io/kestra · error · IllegalArgumentException

Cannot import file of type <type>

Error message

Cannot import file of type <type>

What it means

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.

Source

Thrown at core/src/main/java/io/kestra/core/models/HasSource.java:92

                for (int i = 0; i < sources.size(); i++) {
                    String source = sources.get(i);
                    reader.accept(source, fileName + "(flow number: " + i + ")");
                }
            } else if (fileName.endsWith(".zip")) {

                try (ZipInputStream archive = ProtectedZipInputStream.of(inputStream, zipBombProtection)) {
                    ZipEntry entry;
                    while ((entry = archive.getNextEntry()) != null) {
                        if (entry.isDirectory() || !isYAML(entry.getName())) {
                            continue;
                        }
                        reader.accept(new String(archive.readAllBytes()), entry.getName());
                    }
                }
            } else {
                int extensionIndex = fileName.lastIndexOf('.');
                String type = extensionIndex >= 0 ? fileName.substring(extensionIndex) : fileName;
                throw new IllegalArgumentException("Cannot import file of type " + type);
            }
        }
    }

    private static boolean isYAML(final String fileName) {
        return fileName.endsWith(".yaml") || fileName.endsWith(".yml");
    }
}

View on GitHub (pinned to 823fada927)

Solutions

  1. Convert the file to YAML (.yaml or .yml) before importing.
  2. If importing multiple files, bundle them into a .zip archive of YAML files.
  3. Verify the uploaded filename has the correct extension and is not sanitized away by a proxy.
  4. Check that the multipart upload preserves the original filename.

Example fix

// before
import file: flow.json
// IllegalArgumentException: Cannot import file of type .json

// after
import file: flow.yaml   // or bundle into flows.zip
Defensive patterns

Strategy: validation

Validate before calling

String name = fileUpload.getFilename().toLowerCase();
boolean yaml = name.endsWith(".yaml") || name.endsWith(".yml");
boolean zip = name.endsWith(".zip");
if (!yaml && !zip) {
    throw new IllegalArgumentException("Cannot import file of type " + name);
}

Try / catch

try {
    HasSource.readSourceFile(protection, upload, reader);
} catch (IllegalArgumentException e) {
    return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/f4b4132daaae8e27. Report an issue: GitHub.