diff options
Diffstat (limited to 'MatrixRoomUtils.Core/AuthenticatedHomeServer.cs')
-rw-r--r-- | MatrixRoomUtils.Core/AuthenticatedHomeServer.cs | 12 |
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()!; + } + |