{"record":{"id":"ac9e720ad992b6ed","repo":"halo-dev/halo","slug":"invalid-part-of-policyname","errorCode":null,"errorMessage":"Invalid part of policyName","messagePattern":"Invalid part of policyName","errorType":"validation","errorClass":"ServerWebInputException","httpStatus":400,"severity":"warning","filePath":"application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java","lineNumber":176,"sourceCode":"\n        /** Attachment group {@code metadata.name}. */\n        String getGroupName();\n    }\n\n    public record UploadRequest(MultiValueMap<String, Part> formData) implements IUploadRequest {\n\n        public FilePart getFile() {\n            if (formData.getFirst(\"file\") instanceof FilePart file) {\n                return file;\n            }\n            throw new ServerWebInputException(\"Invalid part of file\");\n        }\n\n        public String getPolicyName() {\n            if (formData.getFirst(\"policyName\") instanceof FormFieldPart form) {\n                return form.value();\n            }\n            throw new ServerWebInputException(\"Invalid part of policyName\");\n        }\n\n        @Override\n        public String getGroupName() {\n            if (formData.getFirst(\"groupName\") instanceof FormFieldPart form) {\n                return form.value();\n            }\n            return null;\n        }\n    }\n}\n","sourceCodeStart":158,"sourceCodeEnd":188,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java#L158-L188","documentation":"UploadRequest.getPolicyName() throws ServerWebInputException (HTTP 400) 'Invalid part of policyName' when the multipart form has no \"policyName\" part or the part is not a FormFieldPart. Unlike getGroupName (which returns null when absent), policyName is mandatory for an upload.","triggerScenarios":"Multipart upload missing the policyName field; policyName sent as a file part by mistake; client forgot to append the form field.","commonSituations":"Frontend bug that only appends the file part; copy-paste of upload code that omitted the policyName append; a third-party uploader that doesn't know Halo requires policyName.","solutions":["Append a policyName form field (string) to the multipart body alongside file.","On the client, always send policyName even if you also send groupName.","Validate that the policy exists before initiating the upload."],"exampleFix":"// before\nfd.append('file', selectedFile); // no policyName\n\n// after\nfd.append('file', selectedFile);\nfd.append('policyName', 'default-policy');","handlingStrategy":"validation","validationCode":"if (!(formData.getFirst(\"policyName\") instanceof FormFieldPart f)) {\n    return Mono.error(new ServerWebInputException(\"Invalid part of policyName\"));\n}","typeGuard":"static boolean hasPolicyNamePart(MultiValueMap<String, Part> fd) {\n    return fd.getFirst(\"policyName\") instanceof FormFieldPart;\n}","tryCatchPattern":null,"preventionTips":["Always append a policyName form field to the upload body.","Treat policyName as mandatory in upload UI, unlike optional groupName.","Validate the chosen policy exists before uploading."],"tags":["validation","attachment","upload","multipart","http-400","required-field"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}