Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Latest commit

 

History

History
131 lines (110 loc) · 4.63 KB

upload-file-to-a-room.md

File metadata and controls

131 lines (110 loc) · 4.63 KB

Upload File to a Room

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

HTTP MethodURLRequires Auth
POST/api/v1/rooms.upload/:ridyes

Path Variables

KeyExample ValueDescription
rid*hdsjjd783hkdThe room ID to which you want to upload the file.

Body Parameters

KeyExample ValueDescription
file*$HOME/example.txtA file name to upload.
msgThis is a message with a fileA message text.
descriptionSimple text fileA description of the file.
tmidvg3h21v31v23The thread message id (if you want upload a file to a thread).
customFields{"priority": "high"}You can add custom fields for messages. For example, set priorities for messages.

You must enable this option and define the validation in the workspace settings. See the Message settings for further information.

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"

{% hint style="info" %} 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. {% endhint %}

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.

{% tabs %} {% tab title=" Authorization" %}

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

{% endtab %}

{% tab title="Invalid Field" %}

{
    "success": false,
    "error": "[invalid-field]",
    "errorType": "invalid-field"
}

{% endtab %}

{% tab title="Unknown Key" %}

{
    "success": false,
    "error": "Match error: Unknown key in field dasd"
}

{% endtab %} {% endtabs %}

Change Log

Version Description
1.0.0 Return Message object on file upload
0.62.0 Added