about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-27 00:39:49 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-27 00:39:49 +0200
commita67276252c8bfcd6b6c5344e70debc6d67d917a9 (patch)
treeaf2806e9729f1013a5db6fbda80a7ad1cd7126fa /MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
parentidk (diff)
downloadMatrixUtils-a67276252c8bfcd6b6c5344e70debc6d67d917a9.tar.xz
Been a while since I last committed
Diffstat (limited to 'MatrixRoomUtils.Core/AuthenticatedHomeServer.cs')
-rw-r--r--MatrixRoomUtils.Core/AuthenticatedHomeServer.cs12
1 files changed, 12 insertions, 0 deletions
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<string> 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<JsonElement>(); + return resJson.GetProperty("content_uri").GetString()!; + } +