1

我正在尝试使用 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.storage.data.id下的存储 ID 。

但是,使用相同的 API 在“Plan”文件夹下查询文件时,我无法获取存储 ID ,

那么 Forge API 有什么方法可以让我们从 Plan 文件夹中下载文件吗?任何帮助表示赞赏。

4

2 回答 2

1

Plan文件夹中列出的item是一个类型,这个类型item在GET versions/:version_idGET items/:item_iditems:autodesk.bim360:Document的响应中不会直接显示存储属性。

要获取物理文件位置,您应该调用GET versions/:version_id/relationships/refs,请参阅此处以获取类似线程:使用 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": {}
            }
        }
    }
],  

fromId之后,您必须通过调用GET versions/:version_id/relationships/refs来访问版本关系数据。

在这种情况下,它是{PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs,那么您将storage在我的调查中看到响应中的属性。

于 2019-03-25T13:11:01.243 回答
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;
    }
于 2019-03-25T16:58:01.667 回答