halo-dev/halo · error · ServerWebInputException
Invalid type of parameter 'file'.
Error message
Invalid type of parameter 'file'.
What it means
Thrown as a ServerWebInputException (HTTP 400) in AttachmentUcEndpoint's PostAttachmentRequest builder when multipartData.getFirst("file") is not an instance of FilePart — the 'file' part is missing entirely or is a FormFieldPart (text) rather than a file upload.
Source
Thrown at application/src/main/java/run/halo/app/core/endpoint/uc/AttachmentUcEndpoint.java:371
* @param multipartData is multipart data from request.
* @return post attachment request data.
*/
public static PostAttachmentRequest from(MultiValueMap<String, Part> multipartData) {
var part = multipartData.getFirst("postName");
String postName = null;
if (part instanceof FormFieldPart formFieldPart) {
postName = formFieldPart.value();
}
part = multipartData.getFirst("singlePageName");
String singlePageName = null;
if (part instanceof FormFieldPart formFieldPart) {
singlePageName = formFieldPart.value();
}
part = multipartData.getFirst("file");
if (!(part instanceof FilePart file)) {
throw new ServerWebInputException("Invalid type of parameter 'file'.");
}
return new PostAttachmentRequest(file, postName, singlePageName);
}
}
}
View on GitHub (pinned to d2f5165f9c)
Solutions
- Attach the binary under a 'file' multipart field with a filename so WebFlux parses it as a FilePart.
- Verify the multipart request includes both the file part and any postName/singlePageName text fields with correct names.
- Confirm Content-Type is multipart/form-data with a valid boundary.
Example fix
// before: curl -F postName=p -F file=@/no/such (or file omitted) // after: curl -F postName=p -F file=@/path/to/attachment.png
Defensive patterns
Strategy: validation
Validate before calling
// ensure the 'file' field is an actual file upload before submit
if (!(formData.get("file") instanceof File)) {
showUserError("Attach a file under the 'file' field");
return;
} Prevention
- Attach the binary as a file upload under the exact 'file' field.
- Confirm the request is multipart/form-data with a boundary.
When it happens
Trigger: POST to the user-center post-attachment upload endpoint where the 'file' multipart part is absent or sent as a plain text field. The instanceof FilePart check fails and the guard throws.
Common situations: Client used the wrong field name; file sent as a string path instead of an attachment; form library did not set a filename/Content-Type; integration test posted only postName/singlePageName fields.
Related errors
- Invalid part of file
- Invalid part of policyName
- Required url is missing.
- Required url is missing.
- Policy name must not be blank
AI-assisted analysis of halo-dev/halo@d2f5165f9c (2026-08-14).
Data as JSON: /api/errors/7d89f77da03d840f.
Report an issue: GitHub.