Skip to content

文件概述

本文档介绍云空间中文件相关能力的基础概念、文件 token 的获取方式和文件的 API 列表。

基础概念

文件是云空间内各种类型的文件的统称,泛指云空间内所有的文件。包括在云空间创建的在线文档、电子表格、多维表格、思维笔记、知识库中的文档等,也包括从本地环境上传的各类文件。

文件 token 获取方式

每个文件都有唯一的 token 作为标识。不同类型的文件的 token 命名可能不同,包括 tokendocument_idfile_tokenapp_tokenspreadsheetToken 等。

放置在文件夹和知识库中的文件,其 token 的获取方式不同,具体如下所示。

文件夹中的文件

如果文件存储在飞书云空间(云盘)的文件夹中,你可通过以下两种方式获取文件的 token:

知识库中的文件

如果文件放置在知识库中,其 URL 中有 wiki 标识,如下图。 此时,该文件也是知识库中的一个节点(node)。

你需调用知识库的获取知识空间节点信息接口,传入该 URL 中的 token 部分,并确保文件类型参数 obj_typewiki,获取该类文件的实际类型 obj_token

image.png

方法列表

以下为文件夹的方法列表。其中,“商店”代表应用商店应用;“自建”代表企业自建应用,了解更多应用相关信息,参考应用类型简介。了解调用服务端 API 的流程,参考流程概述

方法 (API)权限要求(满足任一)访问凭证商店自建
``POST [获取文件元数据](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/meta/batch_query) /open-apis/drive/v1/metas/batch_querydrive:drive 查看、评论、编辑和管理云空间中所有文件 drive:drive.metadata:readonly 查看云空间中文件元数据tenant_access_token user_access_token
``POST [获取文件统计信息](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file-statistics/get) /open-apis/drive/v1/files/:file_token/statisticsdrive:drive 查看、评论、编辑和管理云空间中所有文件 drive:drive.metadata:readonly 查看云空间中文件元数据 drive:drive:readonly 查看、评论和下载云空间中所有文件tenant_access_token user_access_token
``POST [获取文件访问记录](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file-view_record/list)/open-apis/drive/v1/files/:file_token/view_recordscontact:user.base:readonly 获取用户基本信息 drive:file:view_record:readonly 获取文档访问记录tenant_access_token user_access_token
``POST [新建文件](https://open.larkoffice.com/document/ukTMukTMukTM/uQTNzUjL0UzM14CN1MTN)/open-apis/drive/explorer/v2/file/:folderTokendrive:drive 查看、评论、编辑和管理云空间中所有文件 docs:doc 查看、评论、编辑和管理文档 sheets:spreadsheet 查看、评论、编辑和管理电子表格tenant_access_token user_access_token
``POST [复制文件](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/copy)/open-apis/drive/v1/files/:file_token/copydocs:document:copy 复制云文档 drive:drive 查看、评论、编辑和管理云空间中所有文件tenant_access_token user_access_token
``POST [移动文件](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/move)/open-apis/drive/v1/files/:file_token/movedrive:drive 查看、评论、编辑和管理云空间中所有文件 space:document:move 移动云空间文件夹和云文档tenant_access_token user_access_token
``DELETE [删除文件](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/delete)/open-apis/drive/v1/files/:file_tokendrive:drive 查看、评论、编辑和管理云空间中所有文件 space:document:delete 删除云空间文件夹和云文档tenant_access_token user_access_token
``POST [创建文件快捷方式](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/create_shortcut)/open-apis/drive/v1/files/create_shortcutdrive:drive 查看、评论、编辑和管理云空间中所有文件 space:document:shortcut 创建云文档的快捷方式tenant_access_token user_access_token
``POST [搜索文件](https://open.larkoffice.com/document/ukTMukTMukTM/ugDM4UjL4ADO14COwgTN)/open-apis/suite/docs-api/search/objectdrive:drive 查看、评论、编辑和管理云文档所有文件 drive:drive:readonly 查看、评论和下载云空间中所有文件 search:docs:read 搜索云文档user_access_token
``POST [上传文件](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_all)/open-apis/drive/v1/files/upload_alldrive:drive 查看、评论、编辑和管理云空间中所有文件 drive:file 上传、下载文件到云空间 drive:file:upload 上传文件tenant_access_token user_access_token
``POST 分片上传文件 - [/open-apis/drive/v1/files/upload_prepare](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_prepare) - [/open-apis/drive/v1/files/upload_part](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_part) - [/open-apis/drive/v1/files/upload_finish](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_finish)drive:drive 查看、评论、编辑和管理云空间中所有文件 drive:file 上传、下载文件到云空间 drive:file:upload 上传文件tenant_access_token user_access_token
``GET [下载文件](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/download)/open-apis/drive/v1/files/:file_token/downloaddrive:drive 查看、评论、编辑和管理云空间中所有文件 drive:drive:readonly 查看、评论和下载云空间中所有文件 drive:file 上传、下载文件到云空间 drive:file:download 下载云空间下的文件 drive:file:readonly 查看和下载云空间中的文件tenant_access_token user_access_token
``POST [创建导入任务](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/import_task/create)/open-apis/drive/v1/import_tasksdocs:document:import 查看、创建云文档导入任务 drive:drive 查看、评论、编辑和管理云空间中所有文件tenant_access_token user_access_token
``POST[查询导入任务结果](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/import_task/get)/open-apis/drive/v1/import_tasks/:ticket docs:document:import 查看、创建云文档导入任务 drive:drive 查看、评论、编辑和管理云空间中所有文件 drive:drive:readonly 查看、评论和下载云空间中所有文件tenant_access_token user_access_token
``POST 导出云文档 - [/open-apis/drive/v1/export_tasks](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/export_task/create) - [/open-apis/drive/v1/export_tasks/:ticket](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/export_task/get) - [/open-apis/drive/v1/export_tasks/file/:file_token/download](https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/export_task/download)docs:document:export 导出云文档 drive:export:readonly 导出云文档tenant_access_token user_access_token×

内容来源:飞书开放平台 · 自动爬取整理