From a67276252c8bfcd6b6c5344e70debc6d67d917a9 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 27 May 2023 00:39:49 +0200 Subject: Been a while since I last committed --- MatrixRoomUtils.Core/AuthenticatedHomeServer.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'MatrixRoomUtils.Core/AuthenticatedHomeServer.cs') diff --git a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs index 7a1f5de..502fe5b 100644 --- a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs +++ b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs @@ -59,6 +59,18 @@ public class AuthenticatedHomeServer : IHomeServer return rooms; } + public async Task UploadFile(string fileName, Stream fileStream, string contentType = "application/octet-stream") + { + var res = await _httpClient.PostAsync($"/_matrix/media/r0/upload?filename={fileName}", new StreamContent(fileStream)); + if (!res.IsSuccessStatusCode) + { + Console.WriteLine($"Failed to upload file: {await res.Content.ReadAsStringAsync()}"); + throw new InvalidDataException($"Failed to upload file: {await res.Content.ReadAsStringAsync()}"); + } + var resJson = await res.Content.ReadFromJsonAsync(); + return resJson.GetProperty("content_uri").GetString()!; + } + -- cgit 1.5.1