{"record":{"id":"19fac21235795685","repo":"bitwarden/server","slug":"max-file-size-is-sendfilesettinghelper-max-file-s","errorCode":null,"errorMessage":"Max file size is {SendFileSettingHelper.MAX_FILE_SIZE_READABLE}.","messagePattern":"Max file size is (.+?)\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Api/Tools/Controllers/SendsController.cs","lineNumber":264,"sourceCode":"    }\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\n        var (send, data) = model.ToSend(userId, file.FileName!, _sendAuthorizationService);\n        var uploadUrl = await _nonAnonymousSendCommand.SaveFileSendAsync(send, data, model.FileLength.Value);\n        return new SendFileUploadDataResponseModel\n        {\n            Url = uploadUrl,","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/src/Api/Tools/Controllers/SendsController.cs#L246-L282","documentation":"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.","triggerScenarios":"POST /sends/file/v2 with fileLength > 501 MiB (Constants.FileSize501mb).","commonSituations":"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.","solutions":["Reduce the file to under the 501 MiB limit (compress or split).","Verify fileLength is sent in bytes and matches the actual file size.","If self-hosted, check SendFileSettingHelper configuration for any lowered limit.","Show the user the max-size constraint in the UI before upload begins."],"exampleFix":"// before\n{ \"type\": 1, \"fileLength\": 600000000, ... } // > 501 MiB -> 400\n\n// after\n{ \"type\": 1, \"fileLength\": 500000000, ... } // under cap","handlingStrategy":"validation","validationCode":"// Client: enforce the size cap before upload\nconst long MaxSendFileBytes = 501L * 1024 * 1024;\nif (model.FileLength > MaxSendFileBytes) {\n    ShowUser($\"Max Send file size is {MaxSendFileBytes / (1024*1024)} MiB.\");\n    return;\n}\nawait client.PostAsync(\"sends/file/v2\", JsonContent.Create(model));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Surface the size limit in the upload UI before the user picks a file.","Compute fileLength from the actual file size in bytes.","On self-hosted, verify the configured Send file size limit."],"tags":["send","send-file","http-400","file-size","validation","bitwarden-server"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}