bitwarden/server · error · BadRequestException

File metadata is required for file sends.

Error message

File metadata is required for file sends.

What it means

Thrown as BadRequestException (HTTP 400) from POST /sends/file/v2 when model.File is null. A File-type Send requires file metadata (name, etc.) at creation; its absence means the client sent an incomplete payload for the declared file type.

Source

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

    [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,
            FileUploadType = _sendFileStorageService.FileUploadType,
            SendResponse = new SendResponseModel(send)
        };

View on GitHub (pinned to e93b962371)

Solutions

  1. Include the File metadata object (with FileName) in the request body.
  2. Confirm the JSON property name matches the server model ('file').
  3. Validate the client builds model.File whenever Type == File before posting.
  4. Update/align the client SDK to the current Send file contract.

Example fix

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

// after
{ "type": 1, "fileLength": 1000, "file": { "fileName": "doc.pdf" }, "key": "..." }
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static bool HasFileMetadata(SendRequestModel m) => m.Type != SendType.File || m.File is not null;

Prevention

When it happens

Trigger: POST /sends/file/v2 with Type=File but no File object in the body (model.File == null).

Common situations: Client builds the Send request but forgets to attach file metadata; JSON field name mismatch (e.g. 'fileData' vs 'file'); partial/aborted form construction; SDK regression dropping the nested object.

Related errors


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