问题
Following on from my file upload question, I am getting stuck at Step 5 in the documentation. I get a 400 error suggesting some of the data I am sending is incorrect, but I think I have matched the code exactly.
def create_version_for_file(self, file_name, project_id, folder_id, object_id):
url = '{}data/v1/projects/{}/items'.format(self.DOMAIN, project_id)
logger.info('Starting version create at %s for file_name %s, folder %s, object %s',
url, file_name, folder_id, object_id)
data = {
"jsonapi": {"version": "1.0"},
"data": {
"type": "items",
"attributes": {
"displayName": file_name,
"extension": {
"type": "items:autodesk.core:File",
"version": "1.0"
}
},
"relationships": {
"tip": {
"data": {
"type": "versions",
"id": "1"
}
},
"parent": {
"data": {
"type": "folders",
"id": folder_id
}
}
}
},
"included": [
{
"type": "versions",
"id": "1",
"attributes": {
"name": file_name,
"extension": {
"type": "versions:autodesk.core:File",
"version": "1.0"
}
},
"relationships": {
"storage": {
"data": {
"type": "objects",
"id": object_id
}
}
}
}
]
}
response = self.session.post(url, json=data, headers={
'content-type': 'application/vnd.api+json',
'accept': 'application/vnd.api+json'
})
if response.status_code != status.HTTP_201_CREATED:
logger.warn('Version create for %s failed with status %s: %s', file_name, response.status_code,
response.content)
return None
return json.loads(response.content)
However, the request always fails like so:
Upload succeeded for README.md 2017-10-12 16:53:15,943
Starting version create at https://developer.api.autodesk.com/data/v1/projects/b.f19577f2-c4da-428f-9625-bb53bf434cca/items for file_name README.md, folder urn:adsk.wipprod:fs.folder:co.Hx1ePxPtS1e0P-Ib9qudyQ, object urn:adsk.objects:os.object:3a06e38e-4cac-4ffc-981f-0e5c4e4078aab.f19577f2-c4da-428f-9625-bb53bf434cca/d14c3591-d339-4e62-907c-6f0c8b58b743.md
Version create for README.md failed with status 400: {"jsonapi":{"version":"1.0"},"errors":[{"id":"bfbf0a93-c92a-47af-9ce7-a6af48594e44","status":"400","code":"BAD_INPUT","title":"One or more input values in the request were bad","detail":"Request input is invalid for this operation."}]}
Sample values for all of the variables are off to the right in the logs above.
回答1:
This might be setup correctly but maybe you have your storage location created in the incorrect folder. From the tutorial I suggested in the forum post, you need to navigate down one level to avoid the creation of the storage location on the Root folder of BIM 360 Docs. Try going back on your steps and do the followed suggested on the tutorial. Focus on step number 4
Authorization Web Flow (This will return us the code we need to obtain our oauth token)
Rest call to the Authentication API to obtain a 3 legged Token GET call to obtain detail of which Hubs do we have access in BIM 360 Docs (Registration of APP required for BIM 360 API access)
GET call to find the project that has your resource
GET call to find the folder where the upload will happen (Plans, Project File, Drawings).
4.1 Extra step can include the access to a sub-folder.
POST call to create a storage location in the previously defined folder
PUT call to upload file to the storage location
POST call to create the first version of the uploaded file.
Check BIM 360 Docs to see your recently uploaded file.
回答2:
From this forum response, the tutorial is out-of-date and you should use autodesk.bim360:File
(but not autodedsk.bim360:File
as the typo suggests) in place of autodesk.core:File
. There is a more recent example here..
It's still not working but at least my error moved on to The urn must be an unassigned urn prepared by the create storage endpoint, by the same user.
来源:https://stackoverflow.com/questions/46718771/create-file-version-with-autodesk-api