bitwarden/server · error · BadRequestException

Max file size is {SendFileSettingHelper.MAX_FILE_SIZE_READAB

Error message

Max file size is {SendFileSettingHelper.MAX_FILE_SIZE_READABLE}.

What it means

Thrown as BadRequestException (HTTP 400) from POST /sends/file/v2 when model.FileLength exceeds Constants.FileSize501mb. The interpolated message reads 'Max file size is {MAX_FILE_SIZE_READABLE}.' at runtime. This caps single Send files to prevent storage abuse.

Source

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

    }

    [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");
        }

        var (send, data) = model.ToSend(userId, file.FileName!, _sendAuthorizationService);
        var uploadUrl = await _nonAnonymousSendCommand.SaveFileSendAsync(send, data, model.FileLength.Value);
        return new SendFileUploadDataResponseModel
        {
            Url = uploadUrl,

View on GitHub (pinned to e93b962371)

Solutions

  1. Reduce the file to under the 501 MiB limit (compress or split).
  2. Verify fileLength is sent in bytes and matches the actual file size.
  3. If self-hosted, check SendFileSettingHelper configuration for any lowered limit.
  4. Show the user the max-size constraint in the UI before upload begins.

Example fix

// before
{ "type": 1, "fileLength": 600000000, ... } // > 501 MiB -> 400

// after
{ "type": 1, "fileLength": 500000000, ... } // under cap
Defensive patterns

Strategy: validation

Validate before calling

// Client: enforce the size cap before upload
const long MaxSendFileBytes = 501L * 1024 * 1024;
if (model.FileLength > MaxSendFileBytes) {
    ShowUser($"Max Send file size is {MaxSendFileBytes / (1024*1024)} MiB.");
    return;
}
await client.PostAsync("sends/file/v2", JsonContent.Create(model));

Prevention

When it happens

Trigger: POST /sends/file/v2 with fileLength > 501 MiB (Constants.FileSize501mb).

Common situations: User selects a large attachment exceeding the Send file cap; client computes file size in bytes vs MiB mismatch; user on a plan/environment with a lower configured limit; genuine oversized file.

Related errors


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