0

I am trying to download a file from A360 via the Autodesk Forge Data Management API. The documentation states that the JSON returned for an 'Items' or 'Versions' should have a section called 'included.relationships.storage.meta.link.href'.

Step 5: Find the versions of an item

If you only want the latest version, you can simply get the link from the response body of the previous step. In the above example, we can see the storage location of House Design.rvt in the included.relationships.storage.meta.link.href attribute (https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/977d69b1-43e7-40fa-8ece-6ec4602892f3.rvt) which can be used to download the item.

However the JSON returned seems to have this section missing.

i.e. GET projects/:project_id/items/:item_id

Using Postman

https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw

Returns

{      "jsonapi":{  
      "version":"1.0"    },    "links":{  
      "self":{  
         "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw"
      }    },    "data":{  
      "type":"items",
      "id":"urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw",
      "attributes":{  
         "displayName":"Test.dwg",
         "createTime":"2015-01-07T12:54:52.0000000Z",
         "createUserId":"201007051504283",
         "lastModifiedTime":"2015-01-07T12:54:52.0000000Z",
         "lastModifiedUserId":"201007051504283",
         "extension":{  
            "type":"items:autodesk.core:File",
            "version":"1.0",
            "schema":{  
               "href":"https://developer.api.autodesk.com/schema/v1/versions/items:autodesk.core:File-1.0"
            },
            "data":{  

            }
         }
      },
      "links":{  
         "self":{  
            "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw"
         }
      },
      "relationships":{  
         "tip":{  
            "data":{  
               "type":"versions",
               "id":"urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw?version=1"
            },
            "links":{  
               "related":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/tip"
               }
            }
         },
         "versions":{  
            "links":{  
               "related":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/versions"
               }
            }
         },
         "parent":{  
            "data":{  
               "type":"folders",
               "id":"urn:adsk.wipprod:fs.folder:co.UDepmIWYTSSfbYGIUhngIA"
            },
            "links":{  
               "related":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/parent"
               }
            }
         },
         "refs":{  
            "links":{  
               "self":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/relationships/refs"
               },
               "related":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/refs"
               }
            }
         },
         "links":{  
            "links":{  
               "self":{  
                  "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/items/urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw/relationships/links"
               }
            }
         }
      }    },    "included":[  
      {  
         "type":"versions",
         "id":"urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw?version=1",
         "attributes":{  
            "name":"Test.dwg",
            "displayName":"Test.dwg",
            "createTime":"2015-01-07T12:54:52.0000000Z",
            "createUserId":"201007051504283",
            "lastModifiedTime":"2015-01-07T12:54:52.0000000Z",
            "lastModifiedUserId":"201007051504283",
            "versionNumber":1,
            "mimeType":"application/vnd.autodesk.autocad.dwg",
            "storageSize":438112,
            "fileType":"dwg",
            "extension":{  
               "type":"versions:autodesk.core:File",
               "version":"1.0",
               "schema":{  
                  "href":"https://developer.api.autodesk.com/schema/v1/versions/versions:autodesk.core:File-1.0"
               },
               "data":{  

               }
            }
         },
         "links":{  
            "self":{  
               "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1"
            }
         },
         "relationships":{  
            "item":{  
               "data":{  
                  "type":"items",
                  "id":"urn:adsk.wipprod:dm.lineage:ZrHUacBXSa2M1C_Xu_vHOw"
               },
               "links":{  
                  "related":{  
                     "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1/item"
                  }
               }
            },
            "links":{  
               "links":{  
                  "self":{  
                     "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1/relationships/links"
                  }
               }
            },
            "refs":{  
               "links":{  
                  "self":{  
                     "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1/relationships/refs"
                  },
                  "related":{  
                     "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1/refs"
                  }
               }
            },
            "downloadFormats":{  
               "links":{  
                  "related":{  
                     "href":"https://developer.api.autodesk.com/data/v1/projects/a.YnVzaW5lc3M6ZXhjaXRlY2gxNyMyMDE1MDEwNjc2MzA0MDE/versions/urn:adsk.wipprod:fs.file:vf.ZrHUacBXSa2M1C_Xu_vHOw%3Fversion=1/downloadFormats"
                  }
               }
            },
            "derivatives":{  
               "data":{  
                  "type":"derivatives",
                  "id":"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLlpySFVhY0JYU2EyTTFDX1h1X3ZIT3c_dmVyc2lvbj0x"
               },
               "meta":{  
                  "link":{  
                     "href":"https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLlpySFVhY0JYU2EyTTFDX1h1X3ZIT3c_dmVyc2lvbj0x/manifest"
                  }
               }
            },
            "thumbnails":{  
               "data":{  
                  "type":"thumbnails",
                  "id":"dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLlpySFVhY0JYU2EyTTFDX1h1X3ZIT3c_dmVyc2lvbj0x"
               },
               "meta":{  
                  "link":{  
                     "href":"https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLlpySFVhY0JYU2EyTTFDX1h1X3ZIT3c_dmVyc2lvbj0x/thumbnail"
                  }
               }
            }
         }
      }    ] }
4

1 回答 1

0

是的,您是正确的,不幸的是,上传到 A360 的旧文件不会通过 API 公开“数据”字段。开发团队正在努力在未来添加此功能,但我无法告诉您何时可用,对于坏消息感到抱歉。

为了下载一个项目,您首先需要知道您想要哪个版本,然后从中获取 objectKey 和 bucketKey

version.relationships.storage.data.id

这是我的客户端代码:

/////////////////////////////////////////////////////////////////
// Download object from version
//
/////////////////////////////////////////////////////////////////
download (version) {

  // retrieves bucketKey/objectKey from storage Id

  var objectId = this.parseObjectId(
    version.relationships.storage.data.id)

  var uri = `${this.apiUrl}/buckets/` +
    `${objectId.bucketKey}/objects/${objectId.objectKey}`

  var link = document.createElement('a')

  link.download = version.attributes.displayName
  link.href = uri
  link.click()
}

和服务器端(node.js)

//////////////////////////////////////////////////////////////////////
// GET /buckets/:bucketKey/objects/:objectKey
// Download an item version based on { bucketKey, objectKey }
//
/////////////////////////////////////////////////////////////////////
router.get('/buckets/:bucketKey/objects/:objectKey', async (req, res) => {

  try {

    var bucketKey = req.params.bucketKey

    var objectKey = req.params.objectKey

    var forgeSvc = ServiceManager.getService(
      'ForgeSvc')

    var ossSvc = ServiceManager.getService(
      'OssSvc')

    var token = await forgeSvc.get3LeggedTokenMaster(
      req.session)

    var object = await ossSvc.getObject(
      token.access_token,
      bucketKey, objectKey)

    res.end(object)

  } catch(ex) {

    res.status(ex.status || 500)
    res.json(ex)
  }
})

您可以在那里查看项目的完整源代码。

希望有帮助

于 2017-02-13T14:02:37.413 回答