public async Task <AttachmentUploadDataResponseModel> PostAttachment(string id, [FromBody] AttachmentRequestModel request) { var idGuid = new Guid(id); var userId = _userService.GetProperUserId(User).Value; var cipher = request.AdminRequest ? await _cipherRepository.GetOrganizationDetailsByIdAsync(idGuid) : await _cipherRepository.GetByIdAsync(idGuid, userId); if (cipher == null || (request.AdminRequest && (!cipher.OrganizationId.HasValue || !await _currentContext.EditAnyCollection(cipher.OrganizationId.Value)))) { throw new NotFoundException(); } if (request.FileSize > CipherService.MAX_FILE_SIZE) { throw new BadRequestException($"Max file size is {CipherService.MAX_FILE_SIZE_READABLE}."); } var(attachmentId, uploadUrl) = await _cipherService.CreateAttachmentForDelayedUploadAsync(cipher, request.Key, request.FileName, request.FileSize, request.AdminRequest, userId); return(new AttachmentUploadDataResponseModel { AttachmentId = attachmentId, Url = uploadUrl, FileUploadType = _attachmentStorageService.FileUploadType, CipherResponse = request.AdminRequest ? null : new CipherResponseModel((CipherDetails)cipher, _globalSettings), CipherMiniResponse = request.AdminRequest ? new CipherMiniResponseModel(cipher, _globalSettings, cipher.OrganizationUseTotp) : null, }); }