halo-dev/halo · warning · ServerWebInputException
Policy name must not be blank
Error message
Policy name must not be blank
What it means
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.
Source
Thrown at application/src/main/java/run/halo/app/core/attachment/endpoint/AttachmentEndpoint.java:142
* @param policyName storage policy {@code metadata.name}
* @param groupName attachment group {@code metadata.name}
* @param filename custom file name
*/
public record UploadFromUrlRequest(
@Schema(requiredMode = REQUIRED) URL url,
@Schema(requiredMode = REQUIRED) String policyName,
String groupName,
String filename) {
public UploadFromUrlRequest {
if (Objects.isNull(url)) {
throw new ServerWebInputException("Required url is missing.");
}
if (!StringUtils.hasText(policyName)) {
throw new ServerWebInputException("Policy name must not be blank");
}
}
}
/** Multipart payload for uploading an attachment. */
@Schema(types = "object")
public interface IUploadRequest {
/** Attachment file. */
@Schema(requiredMode = REQUIRED)
FilePart getFile();
/** Storage policy {@code metadata.name}. */
@Schema(requiredMode = REQUIRED)
String getPolicyName();
/** Attachment group {@code metadata.name}. */
String getGroupName();View on GitHub (pinned to d2f5165f9c)
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.
Example fix
// before
{ "url": "https://example.com/file.png" } // 400: policyName blank
// after
{ "url": "https://example.com/file.png", "policyName": "default-policy" } Defensive patterns
Strategy: validation
Validate before calling
if (!StringUtils.hasText(policyName)) {
return Mono.error(new ServerWebInputException("Policy name must not be blank"));
} Type guard
static boolean hasPolicyName(String p) { return StringUtils.hasText(p); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Frontend default-policy selection not initialized; user cleared the policy dropdown; integration code assuming a hard-coded policy name that no longer exists.
Related errors
- Required url is missing.
- Invalid part of policyName
- urls must not be empty.
- Invalid part of file
- Required url is missing.
AI-assisted analysis of halo-dev/halo@d2f5165f9c (2026-08-14).
Data as JSON: /api/errors/1b3c9660d3c8a7e0.
Report an issue: GitHub.