{"record":{"id":"b7589a0ba3137cf2","repo":"bitwarden/server","slug":"invalid-content-file-size-hint-is-required","errorCode":null,"errorMessage":"Invalid content. File size hint is required.","messagePattern":"Invalid content\\. File size hint is required\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Api/Tools/Controllers/SendsController.cs","lineNumber":259,"sourceCode":"        }\n\n        var send = model.ToSend(userId, _sendAuthorizationService);\n        await _nonAnonymousSendCommand.SaveSendAsync(send);\n        return new SendResponseModel(send);\n    }\n\n    [Authorize(Policies.Application)]\n    [HttpPost(\"file/v2\")]\n    public async Task<SendFileUploadDataResponseModel> PostFile([FromBody] SendRequestModel model)\n    {\n        if (model.Type != SendType.File)\n        {\n            throw new BadRequestException(\"Invalid content.\");\n        }\n\n        if (!model.FileLength.HasValue)\n        {\n            throw new BadRequestException(\"Invalid content. File size hint is required.\");\n        }\n\n        if (model.FileLength.Value > Constants.FileSize501mb)\n        {\n            throw new BadRequestException($\"Max file size is {SendFileSettingHelper.MAX_FILE_SIZE_READABLE}.\");\n        }\n\n        var file = model.File ?? throw new BadRequestException(\"File metadata is required for file sends.\");\n\n        model.ValidateCreation();\n        var userId = _userService.GetProperUserId(User) ?? throw new InvalidOperationException(\"User ID not found\");\n        var hasPremium = await _hasPremiumAccessQuery.HasPremiumAccessAsync(userId);\n\n        if (!hasPremium && !string.IsNullOrWhiteSpace(model.Emails))\n        {\n            throw new BadRequestException(\"Email verified Sends require a premium membership\");\n        }\n","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/src/Api/Tools/Controllers/SendsController.cs#L241-L277","documentation":"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.","triggerScenarios":"POST /sends/file/v2 with a File-type body where the FileLength property is null or absent in the JSON.","commonSituations":"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.","solutions":["Include the file's byte length in the request body's fileLength field.","Update the client SDK/CLI to a version compatible with the v2 file-send contract.","Verify the JSON payload contains a numeric fileLength before posting.","Inspect the outgoing request with devtools to confirm fileLength is present and > 0."],"exampleFix":"// before\n{ \"type\": 1, \"file\": {...}, \"key\": \"...\" }  // fileLength missing -> 400\n\n// after\n{ \"type\": 1, \"fileLength\": 1048576, \"file\": {...}, \"key\": \"...\" }","handlingStrategy":"validation","validationCode":"// Client: ensure fileLength is set for file Sends\nif (model.Type == SendType.File && model.FileLength is null or <= 0) {\n    ShowUser(\"File size is required.\");\n    return;\n}\nawait client.PostAsync(\"sends/file/v2\", JsonContent.Create(model));","typeGuard":"static bool HasFileLengthHint(SendRequestModel m) => m.Type == SendType.File && m.FileLength.HasValue && m.FileLength.Value > 0;","tryCatchPattern":null,"preventionTips":["Always compute and attach the file's byte length before upload.","Keep the client SDK current with the v2 contract.","Log the outgoing payload during integration testing to confirm fileLength."],"tags":["send","send-file","http-400","validation","bitwarden-server"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}