将文件(图片)附加到对话 [英] Attach a file (picture) to a conversation

查看:97
本文介绍了将文件(图片)附加到对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用REST API将文件附加到对话中.是否有可能?/conversations/{convId}/messages/{itemId}有一个附件",但是可以使用吗?如何?该字段的描述不可用.

I would like to be able to attach a file to a conversation, using the REST API. Is it possible? There is a «attachments» to /conversations/{convId}/messages/{itemId} but is that usable? How? The description of that field is not available.

推荐答案

Circuit的文件API支持附件的上传.收到访问令牌后,您就可以发布带有字节数据的消息.以下示例将上传一个名为test.jpg的文件

The file API of Circuit supports the upload of attachments. As soon as you received your access token you can POST a message with the byte data. The following example wold upload a file with name test.jpg

POST /rest/v2/fileapi HTTP/1.1
Host: local.circuit.com
Authorization: Bearer <access token>
Content-Length: 100
Content-Disposition: attachment; filename="test.jpg"
Cache-Control: no-cache

<your content in binary form here>

通常,我正在使用Postman进行测试,因为它非常易于使用并支持OAuth 2.0令牌生成( https://www.getpostman.com/)

Usually I am using Postman for my tests since it is very easy to use and supports OAuth 2.0 token generation (https://www.getpostman.com/)

您将收到一个类似

{"fileId":"fb211fd6-df53-4b82-824d-986dac47b3e7","attachmentId":"ZmIyMT..."}

如果要验证您的上传,可以通过

If you want to validate your upload you can check it via

GET /rest/v2/fileapi?fileid=fb211fd6-df53-4b82-824d-986dac47b3e7 HTTP/1.1
Host: local.circuit.com
Authorization: Bearer <access token>
Cache-Control: no-cache

好吧,这很容易,既然您已将文件上传到后端,则必须将其附加到对话项中.今天,我们不支持UPDATE,即您需要创建一个新的.

Well that was the easy part, now that you have uploaded the file to the backend you must attach it to a conversation item. Today we do not support UPDATE, i.e. you need to create a new one.

POST /rest/v2/conversations/<conv ID>/messages HTTP/1.1
Host: local.circuit.com
Authorization: Bearer <access token>
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

content=New+Text+Message&attachments=ZmIyMT...

您必须传递生成的附件ID.执行此请求后,文件将附加到对话中.

You have to pass the generated attachment ID. After the execution of this requests the file is attached to the conversation.

如果您跳过第二步,则该文件将不会链接到任何对话,只有发起上传的用户才能访问该文件,并且该文件会在接下来的24-48小时内自动删除.

If you skip the second step the file will not be linked to any conversation, is only accessible by the user who initiates the upload and will be deleted within the next 24 - 48h automatically.

希望这会有所帮助,如果您还有其他问题,请告诉我.

Hope this helps, let me know if you have additional questions.

这篇关于将文件(图片)附加到对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆