Files

Upload a file

Uploads a file—such as an image, video, audio file, or document—to the TalkJS servers, so that you can attach the file to a message.

You can only send content of the type multipart/form-data to this endpoint, not a JSON payload.

For information on how upload a file over HTTP, check the docs of your favorite HTTP client. For example:

When uploading a file, you'll receive an attachmentToken in response to your request. To send a message with the uploaded file as an attachment, use the 'Send a message' resource and include the attachmentToken when sending the message.

Troubleshooting

If you get a 400 Bad Request response, try the following:

  • Check if your code is explicitly setting a Content-type: multipart/form-data header. If so, remove it. Most HTTP libraries autogenerate this header when uploading files, and they will usually set the header to something like Content-Type: multipart/form-data; boundary=a3eb698cd620e766f278e52886c572edcb0e4a97. TalkJS requires the boundary to parse the data.
  • Make sure that the file you're trying to upload has a filename directive set. Many HTTP libraries do this automatically, or allow you to set it explicitly. Setting a filename directive causes the library to generate a header, such as Content-Disposition: form-data; file="This is a txt file."; filename="sample.txt" inside the HTTP body. Many HTTP libraries allow you to give an uploaded file a filename.

If you get a 500 Server Error response, reach out through live support chat.

post/v1/{appId}/files

Request

Path parameters

appIdstring required
Example:abcd1234

A unique identifier of your TalkJS app. You can find your app ID on the Settings page of your dashboard.

Request body multipart/form-data

filestring binary required

File data to upload

filenamestring required

Name of the file to upload

Example request

{
  "filename": "avatar.jpg"
}

Response

File uploaded successfully.

attachmentTokenstring

Attachment token. Use this token to identify a file to attach to a message.

To obtain an attachment token, first upload the file with the 'Upload a file' resource.

Example response

{
  "attachmentToken": "aBcdeFGHijKLMNoPQrsT0123456789"
}

Changes

No recorded changes to this operation across all 1 revision of this API.