简体   繁体   English

来自BIM360 Doc Plans文件夹的API下载文件

[英]API Download File from BIM360 Doc Plans folder

I am trying to download file from Autodesk BIM360 Doc ( https://docs.b360.autodesk.com ) with the Forge API so the files can be then afterward archieved to our local storage. 我正在尝试使用Forge API从Autodesk BIM360 Doc( https://docs.b360.autodesk.com )下载文件,以便随后可以将这些文件保存到我们的本地存储中。

I have managed to download any files from "Project Files" folder using the data management API https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/ , with which i can get the storage id under data.relationships.storage.data.id . 我已设法使用数据管理API从“Project Files”文件夹下载任何文件https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/ ,我可以使用data.relationships.storage.data.id获取存储ID。

however with the same API i cannot get the storage Id when querying files under "Plan" folder, 但是使用相同的API,在“Plan”文件夹下查询文件时无法获取存储ID,

So is there any way with Forge API we can download a file from Plan folder? 那么有什么方法可以使用Forge API从Plan文件夹下载文件吗? any help is appreciated. 任何帮助表示赞赏。

The item listed in the Plan folder is a type of items:autodesk.bim360:Document , this type item won't have storage attribute shown in its responses of GET versions/:version_id and GET items/:item_id directly. Plan文件夹中列出的项目是一种items:autodesk.bim360:Document ,此类型项目的GET版本/:version_idGET项目/:item_id的响应中不会显示存储属性。

To obtain the physical file location, you should call GET versions/:version_id/relationships/refs instead, see here for the similar thread: Download a Document with Autodesk API 要获取物理文件位置,您应该调用GET版本/:version_id / relationships / refs ,请参阅此处查找类似的线程: 使用Autodesk API下载文档

Update for copied item 复制项目的更新

While accessing the relationship data of version of the copied item via GET versions/:version_id/relationships/refs , you would see a data attribute telling the relationship between the copied item and the source item with my experience: 在通过GET版本/: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": {}
            }
        }
    }
],  

Afterward, you have to access the version relationship dat of the fromId via calling GET versions/:version_id/relationships/refs . 之后,您必须通过调用GET版本/:version_id / relationships / refs来访问fromId的版本关系数据。

In this case, it's {PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs , then you will see the storage attribute inside the response with my investigation. 在这种情况下,它是{PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs ,然后您将在我的调查中看到响应中的storage属性。

Just in case anyone else run into the same issue, i post my code with which i finally managed to get the file storage information. 为了防止其他人遇到同样的问题,我发布了我最终设法获取文件存储信息的代码。 However please feel free to suggest other approaches than iteration to the full relationship trees. 但是,请随意建议其他方法,而不是迭代到完整的关系树。

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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM