public async Task <Stream> Create(File file, FileUploadedDelegate onUploaded = null, bool discardEncryption = false) { if (!(await _cloud.GetItemAsync(file.Path, MailRuCloud.ItemType.Folder) is Folder folder)) { throw new DirectoryNotFoundException(file.Path); } Stream stream; bool cryptRequired = _cloud.IsFileExists(CryptFileInfo.FileName, WebDavPath.GetParents(folder.FullPath).ToList()).Any(); if (cryptRequired && !discardEncryption) { if (!_cloud.Account.Credentials.CanCrypt) { throw new Exception($"Cannot upload {file.FullPath} to crypt folder without additional password!"); } // #142 remove crypted file parts if size changed var remoteFile = folder.Files.FirstOrDefault(f => f.FullPath == file.FullPath); if (remoteFile != null) { await _cloud.Remove(remoteFile); } stream = GetCryptoStream(file, onUploaded); } else { stream = GetPlainStream(file, onUploaded); } return(stream); }