bitwarden/server · error · BadRequestException

Invalid content. File size hint is required.

Error message

Invalid content. File size hint is required.

What it means

Thrown as BadRequestException (HTTP 400) from POST /sends/file/v2 when model.FileLength has no value. The file-size hint is mandatory for the v2 two-step upload flow because the server uses it to provision storage and validate the eventual blob size. A null hint means the client omitted required metadata.

Source

Thrown at src/Api/Tools/Controllers/SendsController.cs:259

        }

        var send = model.ToSend(userId, _sendAuthorizationService);
        await _nonAnonymousSendCommand.SaveSendAsync(send);
        return new SendResponseModel(send);
    }

    [Authorize(Policies.Application)]
    [HttpPost("file/v2")]
    public async Task<SendFileUploadDataResponseModel> PostFile([FromBody] SendRequestModel model)
    {
        if (model.Type != SendType.File)
        {
            throw new BadRequestException("Invalid content.");
        }

        if (!model.FileLength.HasValue)
        {
            throw new BadRequestException("Invalid content. File size hint is required.");
        }

        if (model.FileLength.Value > Constants.FileSize501mb)
        {
            throw new BadRequestException($"Max file size is {SendFileSettingHelper.MAX_FILE_SIZE_READABLE}.");
        }

        var file = model.File ?? throw new BadRequestException("File metadata is required for file sends.");

        model.ValidateCreation();
        var userId = _userService.GetProperUserId(User) ?? throw new InvalidOperationException("User ID not found");
        var hasPremium = await _hasPremiumAccessQuery.HasPremiumAccessAsync(userId);

        if (!hasPremium && !string.IsNullOrWhiteSpace(model.Emails))
        {
            throw new BadRequestException("Email verified Sends require a premium membership");
        }

View on GitHub (pinned to e93b962371)

Solutions

  1. Include the file's byte length in the request body's fileLength field.
  2. Update the client SDK/CLI to a version compatible with the v2 file-send contract.
  3. Verify the JSON payload contains a numeric fileLength before posting.
  4. Inspect the outgoing request with devtools to confirm fileLength is present and > 0.

Example fix

// before
{ "type": 1, "file": {...}, "key": "..." }  // fileLength missing -> 400

// after
{ "type": 1, "fileLength": 1048576, "file": {...}, "key": "..." }
Defensive patterns

Strategy: validation

Validate before calling

// Client: ensure fileLength is set for file Sends
if (model.Type == SendType.File && model.FileLength is null or <= 0) {
    ShowUser("File size is required.");
    return;
}
await client.PostAsync("sends/file/v2", JsonContent.Create(model));

Type guard

static bool HasFileLengthHint(SendRequestModel m) => m.Type == SendType.File && m.FileLength.HasValue && m.FileLength.Value > 0;

Prevention

When it happens

Trigger: POST /sends/file/v2 with a File-type body where the FileLength property is null or absent in the JSON.

Common situations: Client SDK version that does not send FileLength; manually constructed request missing the field; JSON deserialization dropping the nullable long; refactored client model that renamed/removed the property.

Related errors


AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13). Data as JSON: /api/errors/b7589a0ba3137cf2. Report an issue: GitHub.