API 从 BIM360 Doc Plans 文件夹下载文件
API Download File from BIM360 Doc Plans folder
我正在尝试使用 Forge API 从 Autodesk BIM360 Doc (https://docs.b360.autodesk.com) 下载文件,以便随后可以将文件存档到我们的本地存储。
我已经使用数据管理 API https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/ 从 "Project Files" 文件夹下载了任何文件,我可以通过它获得data.relationships.storage.data.id 下的存储 ID。
但是使用相同的 API 我在查询 "Plan" 文件夹下的文件时无法获取存储 ID,
那么我们可以使用 Forge API 从 Plan 文件夹下载文件吗?感谢您的帮助。
计划文件夹中列出的项目是 items:autodesk.bim360:Document
的类型,这种类型的项目不会直接在 GET versions/:version_id and GET items/:item_id 的响应中显示存储属性。
要获取物理文件位置,您应该调用GET versions/:version_id/relationships/refs instead, see here for the similar thread:
更新复制的项目
通过GET versions/:version_id/relationships/refs访问复制项的版本关系数据时,您会看到一个数据属性,告诉复制项和源项之间的关系,以我的经验:
"data": [
{
"type": "versions",
"id": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
"meta": {
"refType": "derived",
"fromId": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
"fromType": "versions",
"toId": "urn:adsk.wipprod:fs.file:vf.y3L7YbfAQJWwumMgqjJUxg?version=1",
"toType": "versions",
"direction": "to",
"extension": {
"type": "derived:autodesk.bim360:CopyDocument",
"version": "1.0",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/derived:autodesk.bim360:CopyDocument-1.0"
},
"data": {}
}
}
}
],
之后,您必须通过调用GET versions/:version_id/relationships/refs来访问fromId
的版本关系数据。
在本例中,它是 {PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs
,然后您将在我的调查中看到响应中的 storage
属性。
以防万一其他人 运行 遇到同样的问题,我 post 我的代码终于设法获取了文件存储信息。但是,请随时建议对完整关系树进行迭代以外的其他方法。
internal static ForgeFileInfo getItemVersion(string token, string projectID, string versionID)
{
ForgeFileInfo forgeFileInfo = new ForgeFileInfo();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
versionApi.Configuration.AccessToken = token;
var version = versionApi.GetVersion(projectID, versionID);
string fileType = version.data.attributes.extension.type;
switch (fileType) {
case "versions:autodesk.bim360:File":
//File from Project File library or is regual file
forgeFileInfo.FileName = version.data.attributes.displayName;
forgeFileInfo.FileLocation = version.data.relationships.storage.meta.link.href;
forgeFileInfo.StorageId = version.data.relationships.storage.data.id;
return forgeFileInfo;
case "versions:autodesk.bim360:Document":
//File from Plan Library
var versionRelationship=versionApi.GetVersionRelationshipsRefs(projectID, versionID);
// the GET Relationship has data node where we can get the related document
var relationshipData = new DynamicDictionaryItems(versionRelationship.data);
// let's start iterating the relationship DATA
foreach (KeyValuePair<string, dynamic> relationshipItem in relationshipData)
{
//Have to loop until we found "derived:autodesk.bim360:FileToDocument"
var relationType = relationshipItem.Value.meta.extension.type;
var relation = relationshipItem.Value.meta.direction;
if ("derived:autodesk.bim360:FileToDocument".Equals(relationType))
{
if ("to".Equals(relation))
{
//Go up stream
return getItemVersion(token, projectID, relationshipItem.Value.id);
}
}
else if ("derived:autodesk.bim360:CopyDocument".Equals(relationType))
{
if ("to".Equals(relation))
{
//Go up stream
return getItemVersion(token, projectID, relationshipItem.Value.id);
}
continue;
}
}
break;
}
return forgeFileInfo;
}
我正在尝试使用 Forge API 从 Autodesk BIM360 Doc (https://docs.b360.autodesk.com) 下载文件,以便随后可以将文件存档到我们的本地存储。
我已经使用数据管理 API https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/ 从 "Project Files" 文件夹下载了任何文件,我可以通过它获得data.relationships.storage.data.id 下的存储 ID。
但是使用相同的 API 我在查询 "Plan" 文件夹下的文件时无法获取存储 ID,
那么我们可以使用 Forge API 从 Plan 文件夹下载文件吗?感谢您的帮助。
计划文件夹中列出的项目是 items:autodesk.bim360:Document
的类型,这种类型的项目不会直接在 GET versions/:version_id and GET items/:item_id 的响应中显示存储属性。
要获取物理文件位置,您应该调用GET versions/:version_id/relationships/refs instead, see here for the similar thread:
更新复制的项目
通过GET versions/:version_id/relationships/refs访问复制项的版本关系数据时,您会看到一个数据属性,告诉复制项和源项之间的关系,以我的经验:
"data": [
{
"type": "versions",
"id": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
"meta": {
"refType": "derived",
"fromId": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
"fromType": "versions",
"toId": "urn:adsk.wipprod:fs.file:vf.y3L7YbfAQJWwumMgqjJUxg?version=1",
"toType": "versions",
"direction": "to",
"extension": {
"type": "derived:autodesk.bim360:CopyDocument",
"version": "1.0",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/derived:autodesk.bim360:CopyDocument-1.0"
},
"data": {}
}
}
}
],
之后,您必须通过调用GET versions/:version_id/relationships/refs来访问fromId
的版本关系数据。
在本例中,它是 {PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs
,然后您将在我的调查中看到响应中的 storage
属性。
以防万一其他人 运行 遇到同样的问题,我 post 我的代码终于设法获取了文件存储信息。但是,请随时建议对完整关系树进行迭代以外的其他方法。
internal static ForgeFileInfo getItemVersion(string token, string projectID, string versionID)
{
ForgeFileInfo forgeFileInfo = new ForgeFileInfo();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
versionApi.Configuration.AccessToken = token;
var version = versionApi.GetVersion(projectID, versionID);
string fileType = version.data.attributes.extension.type;
switch (fileType) {
case "versions:autodesk.bim360:File":
//File from Project File library or is regual file
forgeFileInfo.FileName = version.data.attributes.displayName;
forgeFileInfo.FileLocation = version.data.relationships.storage.meta.link.href;
forgeFileInfo.StorageId = version.data.relationships.storage.data.id;
return forgeFileInfo;
case "versions:autodesk.bim360:Document":
//File from Plan Library
var versionRelationship=versionApi.GetVersionRelationshipsRefs(projectID, versionID);
// the GET Relationship has data node where we can get the related document
var relationshipData = new DynamicDictionaryItems(versionRelationship.data);
// let's start iterating the relationship DATA
foreach (KeyValuePair<string, dynamic> relationshipItem in relationshipData)
{
//Have to loop until we found "derived:autodesk.bim360:FileToDocument"
var relationType = relationshipItem.Value.meta.extension.type;
var relation = relationshipItem.Value.meta.direction;
if ("derived:autodesk.bim360:FileToDocument".Equals(relationType))
{
if ("to".Equals(relation))
{
//Go up stream
return getItemVersion(token, projectID, relationshipItem.Value.id);
}
}
else if ("derived:autodesk.bim360:CopyDocument".Equals(relationType))
{
if ("to".Equals(relation))
{
//Go up stream
return getItemVersion(token, projectID, relationshipItem.Value.id);
}
continue;
}
}
break;
}
return forgeFileInfo;
}