使用Autodesk API创建文件版本 [英] Create File Version with Autodesk API

查看:107
本文介绍了使用Autodesk API创建文件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接下来是我的文件上传问题,我陷入了步骤文档中的5 .我收到400错误消息,提示我正在发送的某些数据不正确,但我认为我已经完全匹配了代码.

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.

推荐答案

这可能已正确设置,但也许您在错误的文件夹中创建了存储位置.从我在论坛帖子中建议的教程中,您需要向下导航,以避免在BIM 360 Docs的Root文件夹中创建存储位置.尝试重新执行步骤,并按照教程中建议的步骤进行操作.专注于第4步

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

  1. 授权Web流(这将向我们返回获取oauth令牌所需的代码)

  1. Authorization Web Flow (This will return us the code we need to obtain our oauth token)

对身份验证API的静态调用以获取3足令牌GET调用,以获取我们可以在BIM 360 Docs中访问的集线器的详细信息(访问BIM 360 API所需的APP)

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调用以查找拥有您资源的项目

GET call to find the project that has your resource

GET调用以查找将要进行上传的文件夹(计划,项目文件,工程图).

GET call to find the folder where the upload will happen (Plans, Project File, Drawings).

4.1额外的步骤可以包括访问子文件夹.

4.1 Extra step can include the access to a sub-folder.

POST调用以在先前定义的文件夹中创建存储位置

POST call to create a storage location in the previously defined folder

PUT调用以将文件上传到存储位置

PUT call to upload file to the storage location

POST调用以创建上载文件的第一个版本.

POST call to create the first version of the uploaded file.

检查BIM 360文档以查看您最近上传的文件.

Check BIM 360 Docs to see your recently uploaded file.

这篇关于使用Autodesk API创建文件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆