上传附件到飞书多维表格
此技能通过材料上传流程将文件上传到 Feishu (Lark) 选项附件字段 ::.是一项面向实际任务的技能,主要用于Get source 文件( 本地副本、 URL 下载或 Feishu 信件下载).;Upload to。
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
该技能通过素材上传流程,将文件上传至飞书(Lark)Bitable 的附件字段:
parent_type=bitable_file 参数上传file_tokenfile_token核心设计:这是一个通用型技能,适用于您的应用可访问的任意 Bitable。所有配置均未硬编码。
SkillFileNotFoundError(而非 NameError)SkillInputErrormain.py --help 可成功执行若在您的环境中任意 API 调用失败,请查阅 references/feishu-api-notes.md 中标注的可扩展性接入点。
| 类型 | 说明 | 示例 |
|---|---|---|
local |
本地文件路径 | {"type": "local", "ref": "/tmp/file.pdf"} |
url |
从 HTTP(S) URL 下载 | {"type": "url", "ref": "https://example.com/file.pdf"} |
feishu_message |
飞书消息附件 | {"type": "feishu_message", "ref": {"file_key": "file_xxx"}} |
本技能支持灵活的目标指定方式,适配任意 Bitable:
table_id,解析最快table_name,自动执行查找(调用 API 列出全部表格并按名称匹配)field_id,解析最快field_name,自动执行查找(调用 API 列出全部字段并按名称匹配)record_id:更新已有记录lookup:根据字段值搜索目标记录{
"target": {
"app_token": "bascxxxxxxxxxxxxx",
"table_id": "tblxxxxxxxxxx",
"table_name": "",
"record_id": "recxxxxxxxxxx",
"field_id": "fldxxxxxxxxxx",
"field_name": "附件",
"lookup": {
"field_name": "合同编号",
"field_id": "",
"value": "HT-2026-001"
},
"allow_create_if_lookup_missing": false
},
"source": {
"type": "local",
"ref": "/path/to/file.pdf"
},
"append": true
}
| 参数 | 是否必需 | 说明 |
|---|---|---|
app_token |
是 | Bitable 应用 token(basc...) |
table_id |
否* | 表格 ID(tbl...)。*若未提供 table_name,则为必需 |
table_name |
否* | 表格显示名称。*若未提供 table_id,则为必需 |
record_id |
否 | 记录 ID(rec...)。留空则创建新记录 |
field_id |
否* | 字段 ID。*若未提供 field_name,则为必需 |
field_name |
否* | 字段显示名称。*若未提供 field_id,则为必需 |
lookup |
否 | 用于通过搜索定位 record_id 的配置项 |
allow_create_if_lookup_missing |
否 | 若设为 true,则 lookup 未查到记录时自动创建新记录 |
"lookup": {
"field_name": "合同编号",
"field_id": "",
"value": "HT-2026-001"
}
| 参数 | 是否必需 | 说明 |
|---|---|---|
type |
是 | 取值之一:local、url、feishu_message |
ref |
是 | local:文件路径;url:下载 URL;feishu_message:{file_key, filename} |
| 值 | 行为 |
|---|---|
true |
读取当前附件列表,并将新文件追加至末尾 |
false |
仅用新文件替换附件字段原有内容 |
直接上传至素材上传端点:
POST /open-apis/drive/v1/upload
multipart/form-data 字段:
- file: <文件内容>
- file_name: 文件名
- size: 文件大小(字节)
- parent_type: bitable_file
- parent_node: {app_token}
- extra: {"drive_route_token": "{app_token}"}
以 5MB 分片进行分块上传:
POST /open-apis/drive/v1/chunked_upload/prepare → 获取 upload_idPOST /open-apis/drive/v1/chunked_upload(每片调用一次)→ 获取 etagPOST /open-apis/drive/v1/chunked_upload/finish → 获取 file_token运行前请设置以下环境变量:
export FEISHU_APP_ID=your_app_id export FEISHU_APP_SECRET=your_app_secret export FEISHU_BASE_URL=https://open.feishu.cn # 可选
python scripts/main.py --input payload.local.json
python scripts/main.py --input payload.url.json
python scripts/main.py --input payload.feishu_message.json
python scripts/main.py --input payload.table_name.json
python scripts/main.py --input payload.lookup.json
python scripts/main.py --input payload.create_record.json
使用前请先执行语法检查:
python -m py_compile scripts/*.py
该命令验证以下内容:
{
"ok": true,
"file_token": "vobxxxxxxxxxx",
"app_token": "bascxxxxxxxxxx",
"table_id": "tblxxxxxxxxxx",
"table_name": "合同归档",
"record_id": "recxxxxxxxxxx",
"field_name": "附件",
"field_id": "fldxxxxxxxxxx",
"upload_type": "direct",
"attachment_count": 3,
"mode": "append",
"message": "Successfully uploaded 'report.pdf'..."
}
{
"ok": false,
"error": "Table 'xxx' not found. Available tables: 表 1, 表 2",
"error_type": "resolve_error"
}
| 错误类型 | 原因 | 解决方案 |
|---|---|---|
file_not_found |
本地文件不存在 | 检查文件路径 |
download_failed |
URL 下载失败 | 确认 URL 可访问 |
input_error |
参数无效 | 检查输入 JSON 结构 |
auth_error |
认证凭据无效 | 检查 FEISHU_APP_ID / FEISHU_APP_SECRET |
upload_error |
上传失败 | 检查应用权限配置 |
resolve_error |
表格 / 字段 / 记录未找到 | 核对名称或 ID 是否正确 |
update_error |
记录更新失败 | 确认记录存在 |
本技能未对任何特定 Bitable 进行硬编码:
table_id(直连)或 table_name(API 查询)field_id(直连)或 field_name(API 查询)record_id、lookup 搜索或新建模式详见 references/feishu-api-notes.md,其中包含:
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134万人学习
共49课时 | 82.5万人学习