主题
获取文档内附件的下载地址 #
获取文档内附件的下载地址,需要结合遍历记录接口使用,使用其中返回的附件 source
、type
和 uploadId
来查询附件的下载地址。目前仅支持图片附件及云文档附件
基本信息 #
请求方法:POST
请求路径:/api/v1/openapi/dbt/:file_token/attachment/urls
请求主机:developer.kdocs.cn
限流频次 #
应用类型 | 限额 |
---|---|
测试应用 | 10,000 次/天 |
正式应用 | 10,000,000 次/天 |
权限范围 #
要调用此 API,需要以下权限
权限值 | 显示名称 | 权限说明 |
---|---|---|
access_personal_files | 访问个人文档 | 访问用户个人文档列表 |
Path 参数 #
参数 | 必须 | 类型 | 说明 |
---|---|---|---|
file_token | 是 | string |
Query 参数 #
参数 | 必须 | 类型 | 说明 |
---|---|---|---|
access_token | 是 | string |
Body 参数 #
参数 | 必须 | 类型 | 说明 |
---|---|---|---|
+ attachments | 是 | attachment[] | 附件对象数组(最大长度不得大于 100) |
source | 是 | string | 附件对象来源 |
mime_type | 是 | string | 附件对象 mime type |
key | 是 | string | 附件对象标识 |
请求参数注意项:
请求参数来自于遍历记录接口,需要结合使用
文档中如果具有附件字段,举例如下:
{
"fields": {
"图片和附件": [
{
"fileName": "ddd.gif",
"imgSize": "640*640",
"linkUrl": "",
"size": 1136649,
"source": "upload_ks3",
"type": "image/gif",
"uploadId": "ddd"
}
]
},
"id": "K"
}
source
: 来自于fields对象中附件字段数组的 sourcemime_type
来自于fields对象中附件字段数组的 typekey
来自于fields对象中附件字段数组的 uploadId
返回参数 #
参数 | 必须 | 类型 | 说明 |
---|---|---|---|
code | 是 | integer | 错误码 |
+ data | 是 | data {} | 响应数据 |
+ urls | 是 | attachmentWithUrls[] | 附件下载信息 |
source | 是 | string | 附件对象来源 |
mime_type | 是 | string | 附件对象mime type |
key | 是 | string | 附件对象标识 |
url | 是 | string | 附件下载地址 |
响应参数注意项:
- 云文档附件
url
有效期:10 分钟 - 图片附件
url
有效期:10 分钟 - 云文档附件如果没有权限或发生错误,
url
为空值 - 附件类型若不是图片类型(jpg、png、gif等常见图片类型),
url
为空值
示例 #
请求示例 #
curl --request POST \
--url 'https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx' \
--data '{"attachments":[{"source":"cloud","mime_type":"otl","key":"aaa"},{"source":"upload_ks3","mime_type":"image/png","key":"bbb"},{"source":"cloud","mime_type":"png","key":"ccc"},{"source":"upload_ks3","mime_type":"image/gif","key":"ddd"},{"source":"upload_ks3","mime_type":"docx","key":"eee"}]}'
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}");
Request request = new Request.Builder()
.url("https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx")
.post(body)
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx"
payload := strings.NewReader("{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}")
req, _ := http.NewRequest("POST", url, payload)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
import http.client
conn = http.client.HTTPSConnection("developer.kdocs.cn")
payload = "{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}"
conn.request("POST", "/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx", payload)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
const data = JSON.stringify({
"attachments": [
{
"source": "cloud",
"mime_type": "otl",
"key": "aaa"
},
{
"source": "upload_ks3",
"mime_type": "image/png",
"key": "bbb"
},
{
"source": "cloud",
"mime_type": "png",
"key": "ccc"
},
{
"source": "upload_ks3",
"mime_type": "image/gif",
"key": "ddd"
},
{
"source": "upload_ks3",
"mime_type": "docx",
"key": "eee"
}
]
});
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx");
xhr.send(data);
const http = require("https");
const options = {
"method": "POST",
"hostname": "developer.kdocs.cn",
"port": null,
"path": "/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx",
"headers": {}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({
attachments: [
{source: 'cloud', mime_type: 'otl', key: 'aaa'},
{source: 'upload_ks3', mime_type: 'image/png', key: 'bbb'},
{source: 'cloud', mime_type: 'png', key: 'ccc'},
{source: 'upload_ks3', mime_type: 'image/gif', key: 'ddd'},
{source: 'upload_ks3', mime_type: 'docx', key: 'eee'}
]
}));
req.end();
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx");
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}");
CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://developer.kdocs.cn/api/v1/openapi/dbt/111/attachment/urls?access_token=xxxx");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "{\"attachments\":[{\"source\":\"cloud\",\"mime_type\":\"otl\",\"key\":\"aaa\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/png\",\"key\":\"bbb\"},{\"source\":\"cloud\",\"mime_type\":\"png\",\"key\":\"ccc\"},{\"source\":\"upload_ks3\",\"mime_type\":\"image/gif\",\"key\":\"ddd\"},{\"source\":\"upload_ks3\",\"mime_type\":\"docx\",\"key\":\"eee\"}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
返回示例 #
{
"code": 0,
"data": {
"urls": [
{
"key": "aaa",
"source": "cloud",
"mime_type": "otl",
"url": ""
},
{
"key": "bbb",
"source": "upload_ks3",
"mime_type": "image/png",
"url": "bbb_url"
},
{
"key": "ccc",
"source": "cloud",
"mime_type": "png",
"url": "ccc_url"
},
{
"key": "ddd",
"source": "upload_ks3",
"mime_type": "image/gif",
"url": "ddd_url"
},
{
"key": "eee",
"source": "upload_ks3",
"mime_type": "docx",
"url": ""
}
]
},
"result": "ok"
}
错误码 #
请参考错误码说明