# 查询下载文件

上传文件到File Management后,可查询文件配置信息,也可将文件下载至浏览器默认路径或本地指定路径,本节将介绍如何查询文件信息,以及下载文件。

  • 准备阶段

在上传文件前,您需要获取有效的Access Token, 有关Access Token 的详细说明和具体操作,请参见 Access Token (opens new window)

# 1. 查找文件所属的Hub空间

File Management提供获取Hub列表 (opens new window) 接口,帮助您查询您的账号已注册哪些存储中心(Hub),您可以将文件上传到已注册的存储空间中。

# HTTP请求示例

# 请求 path
GET https://api.bimface.com/bdfs/domain/v1/hubs
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"

# HTTP响应示例

# 响应 200
{
  "code" : "success",
  "data" : [ {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "id" : "10000000000060002",
    "info" : "BIMFACE的hub",
    "name" : "BIMFACE",
    "tenantCode" : "BIMFACE",
    "updateTime" : "2022-02-02 02:02:02"
  } ],
  "message" : "success"
}

# 2. 查找到文件所属的Project

上一步您查找到了您账户注册的存储中心(Hub),假设您已经注册了"BIMFACE"的存储中心,请记住上一节响应正文中的id字段,它代表了HubId(10000000000060002)。

您需要在接口获取项目列表 (opens new window)中使用HubId,来获取可使用的项目列表(Project),,您将在该列表中选择一个项目,查询该项目下的文件信息。

# HTTP请求示例

# 请求 path
GET https://api.bimface.com/bdfs/domain/v1/hubs/10000000000060002/projects
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"

# HTTP响应示例

# 响应 200
{
  "code" : "success",
  "data" : [ {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "hubId" : "10000000000060002",
    "id" : "10000000006016",
    "info" : "图纸对比的项目中心",
    "name" : "图纸对比",
    "tenantCode" : "BIMFACE",
    "thumbnail" : "https://static.bimface.com/bdfs/project/thumbnail/8e21fc91481e42ce805f0db938e04958_200X150.png",
    "type" : "NORMAL",
    "updateTime" : "2022-02-02 02:02:02"
  } ,
    {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "hubId" : "10000000000060002",
    "id" : "10000000005555",
    "info" : "由BIMFACE默认创建的项目,您可以在项目中根据自己的需要存放模型、图纸文件,并进行转换、集成、对比、场景搭建等操作,实现基于云端的可视化浏览与应用开发",
    "name" : "BIMFACE默认项目",
    "tenantCode" : "BIMFACE",
    "thumbnail" : "https://static.bimface.com/bdfs/project/thumbnail/8e21fc91481e42ce805f0db938e04958_200X150.png",
    "type" : "NORMAL",
    "updateTime" : "2022-02-02 02:02:02"
  }],
  "message" : "success"
}

# 3. 查询项目的根文件夹信息

在上一步中,您查找到了文件存放的项目信息,假设您将在项目“图纸对比”中上传文件,请记住该项目的id(10000000006016),您需要在获取项目根文件夹信息 (opens new window)中使用projectId。

这一步将介绍根文件夹的概念,每个项目都有唯一且对应的根文件夹,根文件夹会跟随项目自动创建,所有存放于该项目的文件都位于根文件夹下。

您可在这一步查询根文件夹的信息。根文件夹的信息(例如id和path)可用于获取文件夹下所有文件信息 (opens new window); 由于在BIMFACE中,项目id和根文件夹id相同,您也可直接跳过这一步,将项目Id作为parentId填入相关的接口参数。

# HTTP请求示例

# 请求 path
https://api.bimface.com/bdfs/v1/domain/hubs/10000000000060002/projects/10000000006016/root-folder
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"

# HTTP响应示例

# 响应 200
{
  "code" : "bimfaceservice-0000",
  "data" : {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "10000000006016",
    "folder" : false,
    "id" : "10000000006016",
    "length" : 0,
    "md5" : null,
    "name" : "/",
    "parentId" : null,
    "path" : "/",
    "physicalIndex" : null,
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : null,
    "suffix" : null,
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : null,
    "version" : 1
  },
  "message" : null
}

# 4. 查找到文件所属的文件夹

上一步您已经找到了项目根文件夹,假设您的文件隶属于 "图纸对比"项目,请记住该项目的id和根文件夹id(10000000006016),您将在获取文件夹下的所有文件 (opens new window)接口中使用projectId和parentId。

下列接口将展示项目内所有文件夹和文件的列表,该接口支持您搜索文件夹名(无需完整名,输入关键字即可),或根据文件格式、文件创建时间筛选所需的文件夹或文件。

# HTTP请求示例

# 请求 path
POST https://api.bimface.com/bdfs/data/v1/projects/10000000006016/folders/contents
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"
# 请求 body
{
  "endTime" : "2022-02-04 02:02:02",
  "excludeFolder" : false,
  "parentId" : "10000000006016",
  "startTime" : "2022-02-01 02:02:02",
  "suffix" : "rvt",
  "useFuzzySearch" : false,
}

# HTTP响应示例

# 响应 200
{
  "code" : "success",
  "data" : [
{
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "1938888813662976",
    "folder" : true,
    "id" : "1938888813662976",
    "length" : 0,
    "md5" : null,
    "name" : "dwg图纸测试",
    "parentId" : "10000000006016",
    "physicalIndex" : null,
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : null,
    "suffix" : null,
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : null,
    "version" : 1
  },
  {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "193888881355555",
    "folder" : true,
    "id" : "193888881355555",
    "length" : 0,
    "md5" : null,
    "name" : "bdfs文件夹测试",
    "parentId" : "10000000006016",
    "physicalIndex" : null,
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : null,
    "suffix" : null,
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : null,
    "version" : 1
  },
  {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "193888881366666",
    "folder" : false,
    "id" : "193888881366666",
    "length" : 345345345,
    "md5" : "sdfhskbvnksdiuewriusbndskudf",
    "name" : "BIMFACE示例文件.rvt",
    "parentId" : "10000000006016",
    "physicalIndex" : "a72eaf22f4214a6384429f78b690c983",
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : "10000000021156",
    "suffix" : "rvt",
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : "GENERAL",
    "version" : 1
  },
  {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "193888881377777",
    "folder" : false,
    "id" : "193888881377777",
    "length" : 345345345,
    "md5" : "sdfhskbvnksdiuewriusbnddshih",
    "name" : "BIMFACE示例图纸.dwg",
    "parentId" : "10000000006016",
    "physicalIndex" : "a72eaf22f4214a6384429f777777",
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : "1000000007777",
    "suffix" : "rvt",
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : "GENERAL",
    "version" : 1
  }],
  "message" : "success"
}

# 5. 查询文件信息

在上一步,您已经得到了项目下的文件夹列表和部分文件的列表,如果您的文件在项目根目录下,例如您希望查询的文件是“BIMFACE示例图纸",那么您可以记录下文件id(fileItemId),通过获取文件信息 (opens new window)查询该文件的配置属性,包括名称、访问权限以及其他元数据。

如果您的文件在更深层级,例如在文件夹"bdfs文件夹测试"下,您需要重复上一步,继续调用获取文件夹下的所有文件 (opens new window),直到查询特定的文件信息。

# HTTP请求示例

# 请求 path
GET https://api.bimface.com/bdfs/data/v1/projects/10000000006016/fileItems/meta?fileItemId=193888881377777
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"

# HTTP响应示例

# 响应 200
{
  "code" : "success",
  "data" : {
    "appKey" : "odatvZYUSAWMbdUjTU8HoZXB9tFt6123",
    "createTime" : "2022-02-02 02:02:02",
    "fileItemId" : "193888881377777",
    "folder" : false,
    "id" : "193888881377777",
    "length" : 345345345,
    "md5" : "sdfhskbvnksdiuewriusbnddshih",
    "name" : "BIMFACE示例图纸.dwg",
    "parentId" : "10000000006016",
    "physicalIndex" : "a72eaf22f4214a6384429f777777",
    "projectId" : "10000000006016",
    "status" : "success",
    "storeId" : "1000000007777",
    "suffix" : "rvt",
    "updateTime" : "2022-02-02 02:02:02",
    "uploadMode" : "GENERAL",
    "version" : 1
  },
  "message" : "success"
}

# 6. 下载文件

源文件下载 (opens new window)打包下载压缩文件 (opens new window)两个接口,都可以获取文件。其中获取文件的URL可将下载链接分享给其他人,也可设置链接失效时间,接下来将举例说明使用源文件下载 (opens new window)下载“BIMFACE示例图纸"。

# HTTP请求示例

# 请求 path
GET https://api.bimface.com/bdfs/data/v1/projects/10000000006016/fileItems/downloadUrl?fileItemId=193888881377777
# 请求 header
"Authorization: Bearer cn-e9725999-0b36-4c0e-bdca-38ea88888888"

# HTTP响应示例

# 响应 200
{
  "code" : "success",
  "data" : "http://10.5.67.236:9000/bf-dev-srcfile/32588123676c4905a3f0b145555a6af9?response-content-disposition=attachment%3Bfilename%3D%22QKYY_DK_ST_20211104.rvt%22%3Bfilename%2A%3Dutf-8%27%27QKYY_DK_ST_20211104.rvt&AWSAccessKeyId=bimface&Expires=1648629420&Signature=xjk58U4iy9Pbstb8BS3Q4T9r44Q%3D",
  "message" : "success"
}