我现在能够upload a file并创建initial version for the file但无法更新版本。即使将versions:autodesk.core:File
替换为versions:autodesk.bim360:File
,使用Step 6 of this tutorial中的代码也无效。从错误消息Request contains 0 includes instead of 1
,我似乎需要从步骤5中的示例中获取included
块的一部分,但我不确定它应该是什么样的;鉴于外部relationships
块在步骤5和6之间的格式不匹配,我假设内部内容也有所不同。
def create_version_for_file(self, project_name, file_name, folder_id, object_id, storage_id):
project_id = self.get_project_id_by_name(project_name)
existing_object_id = self.get_version_id_for_file_in_folder(project_name, folder_id, file_name)
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)
if existing_object_id:
logger.info('Creating version for existing object')
data = self._get_version_data_for_existing_file(file_name, object_id, storage_id)
else:
logger.info('Creating version for new object')
data = self._get_version_json_for_new_file(file_name, folder_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)
def _get_version_json_for_new_file(self, file_name, folder_id, object_id):
return {
"jsonapi": {"version": "1.0"},
"data": {
"type": "items",
"attributes": {
"displayName": file_name,
"extension": {
"type": "items:autodesk.bim360: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.bim360:File",
"version": "1.0"
}
},
"relationships": {
"storage": {
"data": {
"type": "objects",
"id": object_id
}
}
}
}
]
}
def _get_version_data_for_existing_file(self, file_name, object_id, storage_id):
return {
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "versions",
"attributes": {
"name": file_name,
"extension": {
"type": "versions:autodesk.bim360:File",
"version": "1.0"
}
},
"relationships": {
"item": {
"data": {
"type": "items",
"id": object_id
}
},
"storage": {
"data": {
"type": "objects",
"id": storage_id
}
}
}
}
}
答案 0 :(得分:3)
您的有效负载是正确的。要创建第二个版本,您必须将您的请求发送到CreateVersion endpoint。
"foobar".to_java(Java::org.jruby.RubyString).getEncoding()
Time.now.to_java(Java::org.jruby.RubyTime).getDateTime()
答案 1 :(得分:0)
你必须错过一些让它无法正常工作的细节,但由于你提供的描述很少,没有人可以根据这个说明...为了创建一个新版本,你首先需要创建一个新的存储位置,将文件上传到该位置,并发布新版本,引用现有项目ID。
或者,如果项目存在,请查看我的节点js样本到upload a file and create a new item or version。
答案 2 :(得分:0)
您更新版本的数据对我来说似乎不正确,请尝试以下步骤。
获得所有这些信息后,您传入的数据将如下所示。
{
"jsonapi": { "version": "1.0" },
"data": {
"type": "versions",
"attributes": {
"name": "v2File.rvt",
"extension": { "type": "versions:autodesk.bim360:File", "version": "1.0"}
},
"relationships": {
"item": { "data": { "type": "items", "id": "urn:adsk.wipprod:dm.lineage:8jehs1iSQGu_wXpZ977bjA" } },
"storage": { "data": { "type": "objects", "id": "urn:adsk.objects:os.object:wip.dm.prod/a7fde689-62cf-49c1-9273-8df976568996.rvt" } }
}
}
}
我能想到的唯一区别是你的objectId不正确。下图是使用API上传的两个版本的证明。