使用Dropbox将Autodesk Design Automation API DWG转换为PDF

时间:2018-06-01 09:17:18

标签: dropbox-api autodesk-forge autodesk-designautomation

您好我正在努力寻找有关如何将DWG文件转换为PDF文件的工作示例。我正在使用Autodesk Design Automation API和Dropbox。我尝试使用以下命令放置WorkItem

{
"Arguments":{
"InputArguments":[
   {
      "Resource": "https://content.dropboxapi.com/2/files/download",
      "Name": "HostDwg",
      "Headers":[
        {
         "Name":"Authorization",
         "Value":"Bearer xxxxxxxxxxxxxxxxxxxxxxxx"

        },{
          "Name":"Dropbox-API-Arg",
          "Value" : {"path":"/original.dwg"}

        }
        ]
   }
],
"OutputArguments":[
   {
      "Name": "Result",
      "HttpVerb": "PUT",
      "Resource": "https://content.dropboxapi.com/2/files/upload",
      "StorageProvider": "Generic",
      "Headers":[
        {
         "Name":"Authorization",
         "Value":"Bearer xxxxxxxxxxxxxx"

        },{
         "Name":"Dropbox-API-Arg",
         "Value": {"path":"/test.pdf"}   

        }

                                    ]

   }
                                          ]
                  },   "ActivityId": "PlotToPDF","Id": ""}

不幸的是我收到以下错误消息

An unexpected 'StartObject' node was found for property named 'Value' when reading from the JSON reader. A 'PrimitiveValue' node was expected.

我认为它与我定义的第二个标题有关,用于指定要下载或上传的文件。我不清楚如何设置这个值是正确的。 如果Iam使用没有Design Automation API的dropbox api,这是有效的。我可以定义一个名为Dropbox-API-Arg的Header,并定义下载/上传路径。

任何帮助将不胜感激。三江源

3 个答案:

答案 0 :(得分:1)

问题是我们希望“Value”为字符串,并且您传递的是一个对象。这是一个有效的例子:

{
  "Arguments": {
    "InputArguments": [
      {
        "Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg",
        "Name": "HostDwg"
      }
    ],
    "OutputArguments": [
      {
        "Name": "Result",
        "HttpVerb": "POST",
        "Resource": "https://content.dropboxapi.com/2/files/upload",
        "Headers" : [
            {
                "Name" : "Authorization",
                "Value" : "Bearer ..."
            },
            {
                "Name":"Content-Type",
                "Value":"application/octet-stream"
            },
            {
                "Name" : "Dropbox-API-Arg",
                "Value" : "{\"path\":\"/test/test.pdf\", \"mode\":\"add\"}"
            }
            ]
      }
    ]
  },
  "ActivityId": "PlotToPDF"
}

答案 1 :(得分:1)

我们改进了设计自动化,因此现在使用Dropbox-API-Arg标头可用于上传和下载。以下内容将在您的保管箱帐户中将DWG转换为PDF:

{
  "Arguments": {
    "InputArguments": [
      {
        "Resource": "https://content.dropboxapi.com/2/files/download",
        "Name": "HostDwg",
        "Headers" : [
          {
            "Name" : "Authorization",
            "Value" : "Bearer ..."
          },
          {
            "Name" : "Dropbox-API-Arg",
            "Value" : "{\"path\":\"/test/test.dwg\"}"
          }
          ]
      }
    ],
    "OutputArguments": [
      {
        "Name": "Result",
        "HttpVerb": "POST",
        "Resource": "https://content.dropboxapi.com/2/files/upload",
        "Headers" : [
          {
            "Name" : "Authorization",
            "Value" : "Bearer ..."
          },
          {
              "Name" : "Content-Type",
              "Value" : "application/octet-stream"
          },
          {
            "Name" : "Dropbox-API-Arg",
            "Value" : "{\"path\":\"/test/test.pdf\", \"mode\":\"add\"}"
          }
          ]
      }
    ]
  },
  "ActivityId": "PlotToPDF"
}

答案 2 :(得分:0)

<强> EDITED 您可以传递Dropbox-API-Arg标题,如下所示

"Name" : "Dropbox-API-Arg",
"Value" : "{\"path\":\"/test/test.pdf\", \"mode\":\"add\"}"

在有效载荷中。

或者,传递arg url编码的字符串也可以。

使用Forge Design Automation,使用以下有效负载与Dropbox配合使用。 您需要传递Arg参数而不是'Dropbox-API-Arg'标题。

arg={"path":"/result.pdf"}在网址中编码为"arg=%7B%22path%22%3A%22%2Fresult.pdf%22%7D"

例如:

在Dropbox中发布result.pdf。

{
    "Arguments": {
        "InputArguments": [
            {
                "Resource": "http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_metric.dwg",
                "Name": "HostDwg"
            }
        ],
        "OutputArguments": [
            {
                "Name": "Result",
                "HttpVerb": "POST",
                "Resource": "https://content.dropboxapi.com/2/files/upload?arg=%7B%22path%22%3A%22%2Fresult.pdf%22%7D",
                "StorageProvider": "Generic",
                "Headers": [
                    {
                        "Name":"Authorization",
                        "Value":"Bearer blahblahblah"
                    },
                    {"Name":"Content-Type",
                     "Value":"application/octet-stream"
                    }
                ]
            }
        ]
    },
    "ActivityId": "PlotToPDF"
}