public async Task UploadTorrent(TorrentUploadViewModel torrent, ElementReference filesRef) { if (torrent == null) { throw new AppException(ExceptionEvent.InvalidParameters, "Torrent can't be null."); } using var content = new MultipartFormDataContent { { new StringContent(JsonSerializer.Serialize(torrent), Encoding.UTF8, "application/json"), "json" } }; foreach (var file in await _fileReaderService.CreateReference(filesRef).EnumerateFilesAsync()) { var fileInfo = await file.ReadFileInfoAsync(); content.Add(new StreamContent(await file.OpenReadAsync()), "files", fileInfo.Name); } await _customHttpClient.SendAsync(HttpMethod.Post, "api/torrents/UploadTorrent", content); }