Matrix is an open network for secure, decentralized communication. I run the Synapse implementation of the Matrix Homeserver on one of my hosts.
I would like to send messages using the client-server API to a specific matrix room. I use an access token and a room id to perform API calls. I can send text messages with the following curl command:
curl --header "Authorization: Bearer my_token" -X POST -d '{"msgtype":"m.text", "body":"my hello world messsage"}' "https://my_homeserver_url/_matrix/client/r0/rooms/"my_room_id"/send/m.room.message"
Unfortunately, I have not yet been able to send an image that is located locally on the computer via the client-server API. According to the documentation you have to select m.image as the message type and reference the image accordingly.
Unfortunately, even after intensive research, I haven't found a working example yet. Can someone point me in the right direction?
I have tried various curl commands and tried to reference the file, either by a link, a path, or a pipe command.
You have to upload the file / image and then attach the file's url to a new event. Here is an example:
1. Uploading the image - link to the spec
You'll get a response like this
2. Sending an event - link to the spec
Be aware that the transaction ID (1212 in the example above) needs to be unique for your access token. So using an uuid (e.g. generated with
uuidgen) might be a good idea.