dfd
This commit is contained in:
@@ -146,6 +146,7 @@ class Matrix(Provider):
|
||||
|
||||
def upload_to_room(self, file_path: str, room_id: str, **kwargs: Any) -> str:
|
||||
"""Upload a file and send it to a specific room."""
|
||||
from models import ProgressFileReader
|
||||
path = Path(file_path)
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"File not found: {file_path}")
|
||||
@@ -167,7 +168,8 @@ class Matrix(Provider):
|
||||
# Upload media
|
||||
upload_url = f"{base}/_matrix/media/v3/upload"
|
||||
with open(path, "rb") as handle:
|
||||
resp = requests.post(upload_url, headers=headers, data=handle, params={"filename": filename})
|
||||
wrapped = ProgressFileReader(handle, total_bytes=int(path.stat().st_size), label="upload")
|
||||
resp = requests.post(upload_url, headers=headers, data=wrapped, params={"filename": filename})
|
||||
if resp.status_code != 200:
|
||||
raise Exception(f"Matrix upload failed: {resp.text}")
|
||||
content_uri = (resp.json() or {}).get("content_uri")
|
||||
|
||||
Reference in New Issue
Block a user