我已经按照该教程中的步骤将文件上传到我的 a360 集线器,没有问题,您是否尝试过仅通过 Rest 调用或 cURL 调用来确保过程正确?我可以告诉你我使用 cURL 的步骤,这样你就可以尝试并告诉我。
注意:使用 cURL 时,我使用 JQ 处理器以更有条理的方式可视化终端中的响应。https://stedolan.github.io/jq/
3条腿认证
步骤 0.1:将用户引导至授权 Web 流程,设置正确的范围
https://developer.api.autodesk.com/authentication/v1/authorize?response_type=code&client_id=xxxxxxxxxx&redirect_uri=http%3A%2F%2Fxxxxx.com%2Foauth%2Fcallback&scope=data:read data:write bucket:create bucket:read数据:创建
步骤 0.2:实现提取授权代码的代码
代码 = xxxxxxxxxxxxx-xxxxxx-xxxxxxxxx
步骤 0.3:交换访问令牌的授权码
curl -v 'https://developer.api.autodesk.com/authentication/v1/gettoken' -X 'POST' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=xxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxx&grant_type=authorization_code&code=xxxxxxxxx-xxxxxxx&redirect_uri=http://xxxxxx.com/oauth/callback' | jq '.'
回复
{“access_token”:“OC5yVHwVyjZRfxQhXJxxxxxxxxx”,“refresh_token”:“o3pKZaUvEsIozWwdyldoHGmLjxxxxxxxxxxx”,“token_type”:“Bearer”,“expires_in”:86399 }
现在我们有了 3 条腿令牌,让我们开始将文件上传到 A360 Hub 的步骤
第 1 步:找到拥有您的资源的中心
curl -X GET -H "Authorization: Bearer xxxxxxxxxxxxxx" "https://developer.api.autodesk.com/project/v1/hubs" | jq '.'
响应将是:
{“jsonapi”:{“版本”:“1.0”},“链接”:{“自我”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs ”}} , "data": [ { "type": "hubs", "id": "a.cGVyc29uYWw6dWxxxxxxxxxxx", // 记下这个 ID "attributes": { "name": "autodesk", "extension": { “类型”:“集线器:autodesk.core:Hub”,“版本”:“1.0”,“模式”:{ “href”:“ https://developer.api.autodesk.com/schema/v1/versions/集线器%3Aautodesk.core%3AHub-1.0 " },“数据”:{}}},“链接”:{“自我”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs/a.YnVzaW5lc3M6YXV0xxxxxxxxxx“ } },“关系”:{“项目”:{“链接”:{“相关”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs/a.YnVzaW5lc3M6YXV0b2Rlc2sxNDU /项目" } } } } }
第 2 步:找到拥有您的资源的项目
curl -X GET -H "Authorization: Bearer OC5yVHwVyxxxxxxxxxxxx" "https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6dWxxxxxxxxxxx/projects" | jq '.'
回复
{“jsonapi”:{“版本”:“1.0”},“链接”:{“self”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs/a。 cGVyc29uYWw6dWxxxxxxxxxxx/projects " } }, "data": [ { "type": "projects", "id": "a.cGVyc29uYW6dxxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ", "attributes": { "name": "Design Files to Share", "extension" :{“类型”:“项目:autodesk.core:项目”,“版本”:“1.0”,“模式”:{“href”:“ https://developer.api.autodesk。com/schema/v1/versions/projects%3Aautodesk.core%3AProject-1.0 " }, "data": {} } }, "links": { "self": { "href": "https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6dWxxxxxxxxxxx/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ " } }, "relationships": { "hub": { "data": { "type": “集线器”,“id”:“a.cGVyc29uYWw6dWxxxxxxxxxxx”},“链接”:{“相关”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs/a. cGVyc29uYWw6dWxxxxxxxxxxx " } } }, "rootFolder": { "data": { "type": "folders", "id": "urn:adsk.wipprod:fs.文件夹:co.BKklEuaHRsiii-mKNxxxxxx”},“元”:{“链接”:{“href”:“https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/folders/urn%3Aadsk.wipprod%3Afs.folder%3Aco.BKklEuaHRsiii-mKNxxxxxx " } } }, "topFolders": { "链接”:{“相关”:{“href”:“ https://developer.api.autodesk.com/project/v1/hubs/a.cGVyc29uYWw6dWxxxxxxxxxxx/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/topFolders ”}}}}}
//第三步:创建存储位置
curl -X POST -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" -H "Authorization: Bearer OC5yVHwVyjZRfxxxxxxxxx" -d '{
"jsonapi": { "version": "1.0" },
"data": {
"type": "objects",
"attributes": {
"name": "lego-racecar.3dm"
},
"relationships": {
"target": {
"data": { "type": "folders", "id": "urn:adsk.wipprod:fs.folder:co.BKklEuaHRsiii-mKNxxxxxx" }
}
}
}
}' "https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/storage" | jq '.'
呼叫的响应
{“jsonapi”:{“版本”:“1.0”},“数据”:{“类型”:“对象”,“id”:“urn:adsk.objects:os.object:wip.dm.prod/6d106e5b -2ac6-41d5-aa1c-b08694xxxxxx.3dm", "relationships": { "target": { "data": { "type": "folders", "id": "urn:adsk.wipprod:fs.folder: co.BKklEuaHRsiii-mKNxxxxxx”},“链接”:{“相关”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/folders/urn%3Aadsk .wipprod%3Afs.folder%3Aco.BKklEuaHRsiii-mKNxxxxxx "} } } } } }
第 4 步:将文件上传到存储位置
curl -X PUT -H "Authorization: Bearer OC5yVHwVyjZRfxQhXJjxxxxxxx" --data-binary @lego-racecar.3dm "https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/6d106e5b-2ac6-41d5-aa1c-b08694xxxxxx.3dm" | jq '.'
回复
{ "bucketKey": "wip.dm.prod", "objectId": "urn:adsk.objects:os.object:wip.dm.prod/6d106e5b-2ac6-41d5-aa1c-b08694xxxxxx.3dm", "objectKey" :“6d106e5b-2ac6-41d5-aa1c-b08694xxxxxx.3dm”,“sha1”:“9c8e51403adc6b3bb6f586433bca66689xxxxxx”,“大小”:107743049,
“contentType”:“应用程序/x-www-form-urlencoded”,“位置”:“ https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/6d106e5b-2ac6-41d5-aa1c-b08694xxxxxx.3dm “}
最后是第 5 步:创建上传文件的第一个版本
curl -X POST -H "Authorization: Bearer OC5yVHwVyjZRfxQhXJjxxxxxxxx" -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" -d '{
"jsonapi": { "version": "1.0" },
"data": {
"type": "items",
"attributes": {
"displayName": "lego-racecar.3dm",
"extension": {
"type": "items:autodesk.core:File",
"version": "1.0"
}
},
"relationships": {
"tip": {
"data": {
"type": "versions", "id": "1"
}
},
"parent": {
"data": {
"type": "folders",
"id": "urn:adsk.wipprod:fs.folder:co.BKklEuaHRsiii-mKNxxxxxx"
}
}
}
},
"included": [
{
"type": "versions",
"id": "1",
"attributes": {
"name": "lego-racecar.3dm",
"extension": {
"type": "versions:autodesk.core:File",
"version": "1.0"
}
},
"relationships": {
"storage": {
"data": {
"type": "objects",
"id": "urn:adsk.objects:os.object:wip.dm.prod/6d106e5b-2ac6-41d5-aa1c-b08694xxxxxx.3dm"
}
}
}
}
]
}' "https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/items" | jq '.'
回复
{“jsonapi”:{“版本”:“1.0”},“链接”:{“self”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a。 cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg “}},“数据”:{“类型”:“项目”,“id”:“urn:adsk.wipprod:dm,2emlvGTyQlB” “属性”:{“displayName”:“lego-racecar.3dm”,“createTime”:“2016-11-02T18:49:51+00:00”,“createUserId”:“TNSUM9VPW79S”,“lastModifiedTime”:“ 2016-11-02T18:49:51+00:00", "lastModifiedUserId": "TNSUM9VPW79S", "extension": { "type": "items:autodesk.core:File", "version": "1.0", "schema": { "href": "https://developer.api.autodesk.com/schema/v1/versions/items%3Aautodesk.core%3AFile-1.0 " }, "data": {} } }, "links": { "self": { " href": " https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg " } }, "关系": { "tip ": { "data": { "type": "versions", "id": "urn:adsk.wipprod:fs.file:vf.BlMbtGTyQ2eMLvZ05rVvAg?version=1" }, "links": { "related": {“href”:“https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/tip " } } }, "版本": { "链接" :{“相关”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/versions ” } } },“父”:{“数据”:{“类型”:“文件夹”,“id”:“urn:adsk.wipprod:fs.folder:co.YgCsk6CGSUSTFeexhncYNw”},“链接”:{“相关”:{“href”:“https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/parent " } } }, "refs": { "links" :{“自我”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/relationships/参考“},“相关”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn%3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/参考" } } }, "链接": { "链接": { "self": { "href": " https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dWUyOTg4MTEzMSMyMDE2MDYxNTM1MDA2NjA2/items/urn %3Aadsk.wipprod%3Adm.lineage%3ABlMbtGTyQ2eMLvZ05rVvAg/relationships/links" } } } } }, "included": [ { "type": "versions", "id": "urn:adsk.wipprod:fs.file:vf.BlMbtGTyQ2eMLvZ0xxxxxx?version=1", "attributes": { “名称”:“lego-racecar.3dm”,“displayName”:“lego-racecar.3dm”,“createTime”:“2016-11-02T18:49:51+00:00”,“createUserId”:“TNSUM9VPxxxxxx ", "lastModifiedTime": "2016-11-02T18:49:51+00:00", "lastModifiedUserId": "TNSUM9VPxxxxxx", "versionNumber": 1, "mimeType": "application/vnd.autodesk.rhinoceros", “存储大小”:107743049,“文件类型”:“3dm”,“扩展”:{“类型”:“版本:autodesk.core:文件”,“版本”:“1.0”,“模式”:{“href”:“https://developer.api.autodesk.com/schema/v1/versions/versions%3Aautodesk.core%3AFile-1.0 " }, "data": {} } }, "links": { "self": { " href": " https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs.file%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1 " } }, "关系”:{“项目”:{“数据”:{“类型”:“项目”,“id”:“urn:adsk.wipprod:dm.lineage:BlMbtGTyQ2eMLvZ0xxxxxxx”},“链接”:{“相关”:{“href”:“https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs.file%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1/item "} } }, "链接“:{“链接”:{“自我”:{“href”:“ https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs。文件%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1/relationships/links " } } }, "refs": { "links": { "self": { "href": "https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs.file%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1/relationships/refs " }, "相关": { "href": " https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs.file%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1/ refs " } } }, "downloadFormats": { "links": { "related": { "href": "https://developer.api.autodesk.com/data/v1/projects/a.cGVyc29uYWw6dxxxxxxxxxxxxxxxxxQwNjEwMTQ3NDA1MQ/versions/urn%3Aadsk.wipprod%3Afs.file%3Avf.BlMbtGTyQ2eMLvZ05rVvAg%3Fversion%3D1/downloadFormats " } } }, "derivatives “:{“数据”:{“类型”:“衍生物”,“id”:“dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkJsTWJ0R1R5UTJlTUx2WjA1clZ2QWc_dmVxxxxxxxxx”},“元”:{“链接”:{“href”:“ https://developer.api.autodesk。 com/modelderivative/v2/designdata/dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkJsTWJ0R1R5UTJlTUx2WjA1clZ2QWc_dmVxxxxxxxx/manifest“ } } },“缩略图”:{“数据”:{“类型”:“缩略图”,“id”:“dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkJsTWJ0R1R5UTJlTUx2WjA1clZ2QWc_dmVxxxxxxxxx”},“元”:{“链接”:{“href”:“ https:// /developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkJsTWJ0R1R5UTJlTUx2WjA1clZ2QWc_dmVyc2lxxxxx/thumbnail “}}},“存储”:{“数据”:{“类型”:“对象”,“idskurn”:“。对象:os.object:wip.dm。prod/6d106e5b-2ac6-41d5-aa1c-b086943xxxxx.3dm”},“元”:{“链接”:{“href”:“https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/6d106e5b-2ac6-41d5-aa1c-b086943xxxxx.3dm “}}}}}]}
它可能包含很多信息,但这是我遵循的过程,并且之前已经工作过。你可以像我之前说的那样尝试它,让 Postman 执行一组 REST 调用,然后再构建你的 ajax 调用。