Skip to content

上传本地文档

在指定目录下上传文档,支持的类型见类型说明

基本信息

请求方法:POST

请求路径:/api/v1/openapi/personal/files/upload

请求主机:developer.kdocs.cn

限流频次

应用类型限额
测试应用
500 次/天
正式应用
100,000 次/天

权限范围

权限值显示名称权限说明
create_personal_files
创建个人文档
创建个人文档

Query 参数

参数必须类型说明
access_token
string

Body 参数

提示

该请求为 multipart/form-data 类型请求

参数必须类型说明
file
file
目标文档,文档本身
parent_id
string
文档所属目录 id,与 parent_path 互斥,同时存在时优先使用 parent_id
parent_path
string[]
文档所属目录,与 parent_id 互斥,同时存在时优先使用 parent_id
path_from_root
boolean
parent_path 参数是否从 我的文档 开始,默认否

参数说明:

提示

在金山文档,存储用户个人文档的根目录为我的文档

应用名path_from_rootparent_path文档创建位置
foo
false
[]
/我的文档/应用/foo
foo
false
["bar", "baz"]
/我的文档/应用/foo/bar/baz
foo
true
[]
/我的文档
foo
true
["bar", "baz"]
/我的文档/bar/baz

提示

我们推荐您将文档创建到您的应用目录下,方便用户理解和管理。

返回参数

参数必须类型说明
code
integer
错误码
+
data
data {}
响应数据

示例

请求示例

curl --request POST \
	--url 'https://developer.kdocs.cn/api/v1/openapi/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc' \
	--header 'content-type: multipart/form-data' \
	--form file=@example.pdf \
	--form 'parent_path=path1,path2'
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n");
Request request = new Request.Builder()
	.url("https://developer.kdocs.cn/api/v1/openapi/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc")
	.post(body)
	.addHeader("content-type", "multipart/form-data")
	.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/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("content-type", "multipart/form-data")

	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 = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n"

headers = { 'content-type': "multipart/form-data" }

conn.request("POST", "/api/v1/openapi/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc", payload, headers)

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/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "POST",
	CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n",
	CURLOPT_HTTPHEADER => [
		"content-type: multipart/form-data"
	],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}
const data = new FormData();
data.append("file", "fileInput.files[0]");
data.append("parent_path", "path1,path2");

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/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");

xhr.send(data);
const http = require("https");

const options = {
	"method": "POST",
	"hostname": "developer.kdocs.cn",
	"port": null,
	"path": "/api/v1/openapi/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	"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("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n");
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/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "content-type: multipart/form-data");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n");

CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://developer.kdocs.cn/api/v1/openapi/personal/files?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "multipart/form-data");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.pdf\"\r\nContent-Type: application/pdf\r\n\r\nfileInput.files[0]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"parent_path\"\r\n\r\npath1,path2\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

返回示例

{
  "code": 0,
  "data": {
    "id": {
      "open_id": "JxdxSDJpnZKRRr0dEKZRuKzClBub7Uz7m1caY_YSxZg",
      "union_id": "-9Yu8Qo2oJirjqhvNofycKzClBub7Uz7m1caY_YSxZg"
    },
    "space": "ok"
  }
}

错误码

请参考错误码说明