批量下载文档(ZIP)
将一个或多个文档下载为单个 ZIP 压缩包。仅可包含以文件形式上传的文档。
1 min read
post/datasets/{dataset_id}/documents/download-zip
Request example
curl --request POST \
--url https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"document_ids": [
"<string>"
]
}'import requests
url = "https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
payload = {
"document_ids": [
"<string>"
]
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"document_ids": [
"<string>"
]
})
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"document_ids": [
"<string>"
]
}',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip"
payload := strings.NewReader("{\n \"document_ids\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"document_ids\": [\n \"<string>\"\n ]\n}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/datasets/{dataset_id}/documents/download-zip')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Post.new(url)
request['Authorization'] = 'Bearer <token>'
request['Content-Type'] = 'application/json'
request.body = '{
"document_ids": [
"<string>"
]
}'
response = http.request(request)
puts response.read_bodyResponse
<file>{
"code": "forbidden",
"message": "Dataset api access is not enabled.",
"status": 403
}{
"code": "forbidden",
"message": "Sorry, you have reached the knowledge base request rate limit of your subscription.",
"status": 403
}{
"code": "forbidden",
"message": "You do not have permission to access this dataset.",
"status": 403
}{
"code": "forbidden",
"message": "No permission.",
"status": 403
}{
"code": "forbidden",
"message": "The API key is not authorized to access this knowledge base.",
"status": 403
}{
"code": "not_found",
"message": "Document not found.",
"status": 404
}{
"code": "not_found",
"message": "Dataset not found.",
"status": 404
}{
"code": "not_found",
"message": "Only uploaded-file documents can be downloaded as ZIP.",
"status": 404
}post/datasets/{dataset_id}/documents/download-zip
Authorization
Path parameters
知识库 ID,通过 获取知识库列表 获取。使用限定范围的密钥时,从 Dify 页面 URL 复制 ID。
Body
application/jsonResponses
application/zip
包含所请求文档的 ZIP 压缩包。