{"record":{"id":"1b3c9660d3c8a7e0","repo":"halo-dev/halo","slug":"policy-name-must-not-be-blank","errorCode":null,"errorMessage":"Policy name must not be blank","messagePattern":"Policy name must not be blank","errorType":"http","errorClass":"ServerWebInputException","httpStatus":400,"severity":"warning","filePath":"application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java","lineNumber":142,"sourceCode":"     * @param policyName storage policy {@code metadata.name}\n     * @param groupName attachment group {@code metadata.name}\n     * @param filename custom file name\n     */\n    public record UploadFromUrlRequest(\n            @Schema(requiredMode = REQUIRED) URL url,\n\n            @Schema(requiredMode = REQUIRED) String policyName,\n\n            String groupName,\n\n            String filename) {\n        public UploadFromUrlRequest {\n            if (Objects.isNull(url)) {\n                throw new ServerWebInputException(\"Required url is missing.\");\n            }\n\n            if (!StringUtils.hasText(policyName)) {\n                throw new ServerWebInputException(\"Policy name must not be blank\");\n            }\n        }\n    }\n\n    /** Multipart payload for uploading an attachment. */\n    @Schema(types = \"object\")\n    public interface IUploadRequest {\n\n        /** Attachment file. */\n        @Schema(requiredMode = REQUIRED)\n        FilePart getFile();\n\n        /** Storage policy {@code metadata.name}. */\n        @Schema(requiredMode = REQUIRED)\n        String getPolicyName();\n\n        /** Attachment group {@code metadata.name}. */\n        String getGroupName();","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java#L124-L160","documentation":"The compact constructor of UploadFromUrlRequest also validates policyName: it throws ServerWebInputException (HTTP 400) 'Policy name must not be blank' when policyName is null or whitespace. policyName is the metadata.name of the attachment storage policy the upload should use.","triggerScenarios":"POST upload-from-url with policyName omitted, null, or whitespace-only; passing a policy display name instead of its metadata.name; referencing a policy that was deleted so the caller leaves the field blank.","commonSituations":"Frontend default-policy selection not initialized; user cleared the policy dropdown; integration code assuming a hard-coded policy name that no longer exists.","solutions":["Send a valid attachment policy metadata.name in policyName.","Fetch available policies first and ensure the chosen one exists before submitting.","On the client, require a non-empty policy selection before enabling upload."],"exampleFix":"// before\n{ \"url\": \"https://example.com/file.png\" } // 400: policyName blank\n\n// after\n{ \"url\": \"https://example.com/file.png\", \"policyName\": \"default-policy\" }","handlingStrategy":"validation","validationCode":"if (!StringUtils.hasText(policyName)) {\n    return Mono.error(new ServerWebInputException(\"Policy name must not be blank\"));\n}","typeGuard":"static boolean hasPolicyName(String p) { return StringUtils.hasText(p); }","tryCatchPattern":null,"preventionTips":["Fetch available policies and require a selection before upload.","Send the policy metadata.name, not its display name.","Default the policy field to a known-good policy in the UI."],"tags":["validation","attachment","upload","http-400","required-field","record-constructor"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}