matrix-nio
matrix-nio copied to clipboard
Correct Way to Upload Images - (encrypted)
Hi I'm trying to find the correct way to send images, e2e encrypted using this client.
I came across this example: https://github.com/poljar/matrix-nio/blob/fc9f5e3eda25ad65936aeb95412a26af73cedf6a/nio/client/async_client.py#L2475, which does not work for me
My fix to that was this
async def send_jpg_image(self, room_id, message, filename):
try:
file_stat = os.stat(filename)
async with aiofiles.open(filename, "r+b") as f:
resp, maybe_keys = await self.upload(f,
content_type="image/jpeg",
filename=filename,
filesize=file_stat.st_size,
encrypt=False)
await self.room_send(
room_id,
message_type="m.room.message",
content = {
"msgtype": "m.file",
"url": resp.content_uri,
"body": message
})
except Exception as err:
print(err)
This works, however there is no image thumbnail/preview. It just shows up as a file upload. I want the preview to show up, like when I upload an image using the element client.
Also this example does not seem to be e2e encrypted, just adding encrypt=True to the upload does not seem to solve the problem, since then the image seems corrupt
I also tried to add the following data into the content argument of self.room_send
await self.room_send(
room_id,
message_type="m.room.message",
content = {
"msgtype": "m.file",
"url": resp.content_uri,
"body": message,
"info": {
"h": 480,
"w": 800,
"thumbnail_url": resp.content_uri ,
"mimetype": "image/jpeg",
"size": file_stat.st_size
}
})
But i still cant see a preview of my image.