我正在尝试使用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/从“项目文件” 文件夹中下载了任何文件,利用该文件我可以在 data.relationships下获得存储ID。 storage.data.id 。
但是使用相同的API查询“计划” 文件夹下的文件时,我无法获得存储ID,
那么Forge API有什么办法可以从Plan文件夹下载文件?任何帮助表示赞赏。
答案 0 :(得分:0)
“计划”文件夹中列出的项目是一种items:autodesk.bim360:Document
,这种类型的项目不会直接在其GET versions/:version_id和GET items/:item_id的响应中显示存储属性。
要获取物理文件的位置,您应该调用GET versions/:version_id/relationships/refs,有关类似线程,请参见此处:Download a Document with Autodesk API
更新复制的项目
通过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
的版本关系dat。
在这种情况下,它是{PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs
,然后您将在调查中看到storage
属性。
答案 1 :(得分:0)
以防万一其他人遇到相同的问题,我发布了我的代码,最终我设法通过这些代码获取了文件存储信息。但是,请随意为迭代整个关系树建议其他方法。
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;
}