{"record":{"id":"7d89f77da03d840f","repo":"halo-dev/halo","slug":"invalid-type-of-parameter-file","errorCode":null,"errorMessage":"Invalid type of parameter 'file'.","messagePattern":"Invalid type of parameter 'file'\\.","errorType":"validation","errorClass":"ServerWebInputException","httpStatus":400,"severity":"error","filePath":"application/src/main/java/run/halo/app/core/endpoint/uc/AttachmentUcEndpoint.java","lineNumber":371,"sourceCode":"         * @param multipartData is multipart data from request.\n         * @return post attachment request data.\n         */\n        public static PostAttachmentRequest from(MultiValueMap<String, Part> multipartData) {\n            var part = multipartData.getFirst(\"postName\");\n            String postName = null;\n            if (part instanceof FormFieldPart formFieldPart) {\n                postName = formFieldPart.value();\n            }\n\n            part = multipartData.getFirst(\"singlePageName\");\n            String singlePageName = null;\n            if (part instanceof FormFieldPart formFieldPart) {\n                singlePageName = formFieldPart.value();\n            }\n\n            part = multipartData.getFirst(\"file\");\n            if (!(part instanceof FilePart file)) {\n                throw new ServerWebInputException(\"Invalid type of parameter 'file'.\");\n            }\n\n            return new PostAttachmentRequest(file, postName, singlePageName);\n        }\n    }\n}\n","sourceCodeStart":353,"sourceCodeEnd":378,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/core/endpoint/uc/AttachmentUcEndpoint.java#L353-L378","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: curl -F postName=p -F file=@/no/such  (or file omitted)\n// after:  curl -F postName=p -F file=@/path/to/attachment.png","handlingStrategy":"validation","validationCode":"// ensure the 'file' field is an actual file upload before submit\nif (!(formData.get(\"file\") instanceof File)) {\n    showUserError(\"Attach a file under the 'file' field\");\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Attach the binary as a file upload under the exact 'file' field.","Confirm the request is multipart/form-data with a boundary."],"tags":["attachment","upload","multipart","validation","user-center"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}