上传素材
POST
/open-apis/drive/v1/medias/upload_all
自建应用商店应用
cURL示例
Python示例
import os
import requests
from requests_toolbelt import MultipartEncoder
def upload_media():
file_path = "path/demo.jpeg"
file_size = os.path.getsize(file_path)
url = "https://open.feishu.cn/open-apis/drive/v1/medias/upload_all"
form = {'file_name': 'demo.jpeg',
'parent_type': 'doc_image',
'parent_node': 'doccnFivLCfJfblZjGZtxgabcef',
'size': str(file_size),
'file': (open(file_path, 'rb'))}
multi_form = MultipartEncoder(form)
headers = {
'Authorization': 'Bearer t-e13d5ec1954e82e458f3ce04491c54ea8c9abcef', ## 获取tenant_access_token, 需要替换为实际的token
}
headers['Content-Type'] = multi_form.content_type
response = requests.request("POST", url, headers=headers, data=multi_form)
if __name__ == '__main__':
upload_media()
请求体示例
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file_name";
demo.jpeg
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="parent_type";
doc_image
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="parent_node";
doccnFivLCfJfblZjGZtxgabcef
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="size";
1024
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="checksum";
12345678
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="extra";
{"test":"test"}
---7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file";
Content-Type: application/octet-stream
file binary
---7MA4YWxkTrZu0gW
错误码
HTTP状态码 | 错误码 | 描述 | 排查建议 |
---|---|---|---|
200 | 1061001 | internal error. | 服务内部错误,包括超时,错误码没处理。 |
400 | 1061002 | params error. | 请检查请求参数是否正确。 |
404 | 1061003 | not found. | 请确认对应资源是否存在。 |
403 | 1061004 | forbidden. | 请确认当前身份是否有对应上传节点的的权限,如用户是否有上传到指定doc的编辑权限。 |
401 | 1061005 | auth failed. | 请使用正确身份访问该接口。 |
200 | 1061006 | internal time out. | 服务内部超时,可稍后再试。 |
404 | 1061007 | file has been delete. | 请确认对应节点未被删除。 |
400 | 1061008 | invalid file name. | 请检查文件名,当前文件名过长或者为空。 |
400 | 1061021 | upload id expire. | 上传事务过期,请重头开始上传。 |
400 | 1061041 | parent node has been deleted. | 请确认上传点未被删除。 |
400 | 1061042 | parent node out of limit. | 在当前上传点上传过多素材,请更换上传点。 |
400 | 1061043 | file size beyond limit. | 请检查文件长度以避免超出限制。具体限制请参考 |
400 | 1061044 | parent node not exist. | 请确认上传点是否存在。 |
200 | 1061045 | can retry. | 内部可重试错误,请稍后重试。 |
400 | 1061109 | file name cqc not passed. | 请确保上传的文件和文件名合规。 |
400 | 1061113 | file cqc not passed. | 请确保上传的文件和文件名合规。 |
400 | 1061101 | file quota exceeded. | 租户容量超限,请确保租户有足够容量进行上传。 |
202 | 1062004 | cover generating. | 缩略图正在生成中,请稍后再试。 |
202 | 1062005 | file type not support cover. | 此文件类型不支持生成缩略图。 |
202 | 1062006 | cover no exist. | 缩略图正在生成中,请稍后再试。 |
400 | 1062007 | upload user not match. | 请确保当前请求身份和上传任务的身份为同一个。 |
400 | 1062008 | checksum param Invalid. | 请确保文件/文件块的checksum正确。 |
400 | 1062009 | the actual size is inconsistent with the parameter declaration size. | 实际传输的文件大小和参数说明的大小不符合一致。 |
400 | 1062010 | block missing, please upload all blocks. | 部分文件分片缺失,请确保所有文件分片上传完成。 |
400 | 1062011 | block num out of bounds. | 上传过多文件分片,请确保上传的为对应文件。 |
400 | 1061547 | attachment parent-child relation number exceed. | 特指上传到文档的素材超出限 制。 |
400 | 1061061 | user quota exceeded. | 个人容量超限,请确保个人有足够容量进行上传。 |
403 | 1061073 | no scope auth. | 没有申请接口权限。 |
400 | 1062012 | file copying. | 文件正在拷贝中。 |
400 | 1062013 | file damaged. | 文件拷贝失败。 |
403 | 1062014 | dedupe no support. | 不允许秒传。 |
400 | 1062051 | client connect close. | 客户端断开连接。 |
400 | 1062505 | parent node out of size. | 云空间单树大小超限制(40W限制 )。 |
400 | 1062506 | parent node out of depth. | 云空间目录深度超限制(15限制)。 |
400 | 1062507 | parent node out of sibling num. | 云空间目录下挂载数量超过限制(单层1500限制 )。 |
400 | 1061101 | file quota exceeded. | 租户容量超限,请确保租户有足够容量进行上传。 |
400 | 1061061 | user quota exceeded. | 个人容量超限,请确保个人有足够容量进行上传。 |
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://open.feishu.cn/open-apis/drive/v1/medias/upload_all' \
--header 'Authorization;' \
--header 'Content-Type: multipart/form-data; boundary=---7MA4YWxkTrZu0gW' \
--form 'file=@""' \
--form 'file_name="test.txt"' \
--form 'parent_type="doc_image"' \
--form 'parent_node="doccn123456"' \
--form 'size="1024"'
响应示例响应示例
{
"code": 0,
"msg": "success",
"data": {
"file_token": "boxcnrHpsg1QDqXAAAyachabcef"
}
}
请求参数
Header 参数
Content-Type
string
必需
示例值:
multipart/form-data; boundary=---7MA4YWxkTrZu0gW
Authorization
string
必需
默认值:
Bearer {{access_token}}
Body 参数multipart/form-data
file
file
必需
file_name
必需
示例值:
test.txt
parent_type
必需
示例值:
doc_image
parent_node
必需
示例值:
doccn123456
size
必需
示例值:
1024
checksum
可选
示例值:
12345678
extra
可选
示例值:
{"test":"test"}
返回响应
修改于 2023-01-13 05:56:47