注意:上传文件大小不能超过 10M,超过会上传失败。
注意:在调用程序中,如果返回429或503错误,说明接口被限流了,请稍微暂停一下并重试。详见接口限流说明。
所需要的 HTTP Header: * Authorization – 获取到的token * restrict-access – 是否限制访问权限。注意:这个 API 并没有考虑这个属性的值,而是有这个属性即可。最后,需要使用 HTTP multipart/form-data 形式。
Path: /{org_name}/{app_name}/chatfiles
HTTP Method: POST
Request Headers: {“restrict-access”:true,”Authorization”:”Bearer ${token}”}
URL Params: 无
Request Body: 文件表单项
Response Body: 详情参见示例返回值,返回的 JSON 数据中会包含除上述属性之外的一些其他信息,均可以忽略。
可能的错误码:401(未授权[无token、token错误、token过期])、5xx。详见:服务器端 REST API 常见错误码
curl 示例:
curl --verbose --header "Authorization: Bearer YWMtz1hFWOZpEeOPpcmw1FB0RwAAAUZnAv0D7y9-i4c9_c4rcx1qJDduwylRe7Y" --header "restrict-access:true" --form file=@/Users/stliu/a.jpg https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles
或者查看我们的示例代码。
Response 示例:
{
"action" : "post",//POST请求
"application" : "ecc6b6c0-e668-11e3-9d00-896af7b8411e",
"path" : "/chatfiles",
"uri" : "https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles", //上传路径
"entities" : [ {
"uuid" : "0c0f5f3a-e66b-11e3-8863-f1c202c2b3ae",//文件唯一ID,指定是哪个文件,发送消息时需要用到。
"type" : "chatfile",
"share-secret" : "DRGM8OZrEeO1vafuJSo2IjHBeKlIhDp0GCnFu54xOF3M6KLr" //上传成功后返回,发送消息时需要用到。
}],
"timestamp" : 1401283318916,
"duration" : 1841,//上传时间
"organization" : "easemob-demo",
"applicationName" : "chatdemoui"
}