AutoDesk Forge API上传文件失败

时间:2018-04-30 22:42:43

标签: autodesk-forge autodesk autodesk-data-management

我们正在关注tutorial for uploading a file,但似乎无法成功完成最后一步(步骤5:创建上传文件的第一个版本)。我们能够成功解析目标项目和文件夹,创建存储位置,并将文件上传到存储位置。

然后我们尝试调用端点在文件夹中创建文件的版本。

POST  https://developer.api.autodesk.com/data/v1/projects/{the project id}/items
{
  "jsonapi": {
    "version": "1.0"
  },
  "data": {
    "type": "items",
    "attributes": {
      "displayName": "Sample.jpg",
      "extension": {
        "type": "items:autodesk.core:File",
        "version": "1.0"
      }
    },
    "relationships": {
      "tip": {
        "data": {
          "type": "versions",
          "id": "1"
        }
      },
      "parent": {
        "data": {
          "type": "folders",
          "id": "{the project id}"
        }
      }
    }
  },
  "included": [
    {
      "type": "versions",
      "id": "1",
      "attributes": {
        "name": "Sample.jpg",
        "extension": {
          "type": "versions:autodesk.core:File",
          "version": "1.0"
        }
      },
      "relationships": {
        "storage": {
          "data": {
            "type": "objects",
            "id": "{object id return from file upload}"
          }
        }
      }
    }
  ]
}

响应始终为400(错误请求),并提供以下详细信息:

{
  "jsonapi": {
   "version": "1.0"
  },
  "errors": [
    {
        "id": "ed1ae266-ebe5-4414-999a-8b6302317639",
        "status": "400",
        "code": "BAD_INPUT",
        "title": "One or more input values in the request were bad",
        "detail": "Request input is invalid for this operation."
    }
  ]
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

(由于初学者的声誉,我无法评论,因此写作答案)

您没有提及是否要上传到BIM 360团队或BIM 360文档管理项目,所以我将假设 BIM 360团队,因为这是本教程所基于的内容

注意:要上传到BIM 360文档管理,必须使用*:autodesk.bim360:File,而不是*:autodesk.core:File

关于您的请求有效负载,您需要提供文件夹URN ,而不是项目ID:

"parent": {
  "data": {
    "type": "folders",
    "id": "{folderURN}"
  }
}