Upload File to a Room

Post a message with the attached file to a dedicated room.

HTTP MethodURLRequires Auth

POST

/api/v1/rooms.upload/:rid

Path Variables

KeyExample ValueDescription

rid*

hdsjjd783hkd

The room ID to which you want to upload the file.

Body Parameters

KeyExample ValueDescription

file*

$HOME/example.txt

A file name to upload.

msg

This is a message with a file

A message text.

description

Simple text file

A description of the file.

tmid

vg3h21v31v23

The thread message id (if you want upload a file to a thread).

Example Call

curl "http://localhost:3000/api/v1/rooms.upload/GENERAL" \
    -F file=@$HOME/example.txt \
    -F "msg=This is a message with a file" \
    -F "description=Simple text file" \
    -H "X-Auth-Token: ijFlJ1yfidXhwEYY284Anoq_iEsOeMMVCupzNhX22tB" \
    -H "X-User-Id: hw5DThnhQmxDWnavu"

For some file types, when uploading via curl, you may need to set the mime type.

With some file types, curl will upload the file as application/octet-stream. You can pass a custom mime type like this: -F "file=@file.wav;type=audio/wav" to specify the type.

Example Response

Success

{
    "message": {
        "_id": "XhqGxkXYtcYba2F9K",
        "rid": "GENERAL",
        "ts": "2022-06-29T07:34:33.736Z",
        "msg": "This is a message with a file",
        "file": {
            "_id": "pw6oyrjBStWwMdeMv",
            "name": "example.txt",
            "type": "text/plain"
        },
        "files": [
            {
                "_id": "pw6oyrjBStWwMdeMv",
                "name": "example.txt",
                "type": "text/plain"
            }
        ],
        "attachments": [
            {
                "ts": "1970-01-01T00:00:00.000Z",
                "title": "example.txt",
                "title_link": "/file-upload/pw6oyrjBStWwMdeMv/example.txt",
                "title_link_download": true,
                "type": "file",
                "description": "Simple text file"
            }
        ],
        "u": {
            "_id": "g8aroJivN5R32TxCm",
            "username": "rodriq",
            "name": "Rodriq"
        },
        "_updatedAt": "2022-06-29T07:34:33.811Z",
        "urls": [],
        "md": [
            {
                "type": "PARAGRAPH",
                "value": [
                    {
                        "type": "PLAIN_TEXT",
                        "value": "This is a message with a file"
                    }
                ]
            }
        ]
    },
    "success": true
}

Error

Any of the following errors can occur:

  • Authorization: Requires an authentication token for the request to be made.

  • Invalid Field: Occurs when the file parameter is invalid.

  • Unknow Key: Occurs when any extra payload is sent in the request.

{
    "success": false,
    "error": "unauthorized"
}

Change Log

VersionDescription

1.0.0

Return Message object on file upload

0.62.0

Added

Last updated

Rocket.Chat versions receive support for six months after release.