【问题标题】:Autodesk.DesignAutomation returning Unexpected token S in JSON at position 0 when calling the workitem api调用工作项 api 时,Autodesk.DesignAutomation 在位置 0 处以 JSON 格式返回 Unexpected token S
【发布时间】:2020-02-02 20:39:28
【问题描述】:

我遇到了一个新的提取问题

handleSendToForge(e) {
        e.preventDefault();


        let formData = new FormData();
        formData.append('data', JSON.stringify({
            Width: this.state.Width,
            Length: this.state.Length,
            Depth: this.state.Depth,
            Thickness: this.state.Thickness,
            BottomThickness: this.state.BottomThickness,
            rebarSpacing: this.state.rebarSpacing,
            outputrvt: this.state.outputrvt,
            bucketId: this.state.bucketId,
            activityId: 'RVTDrainageWebappActivity',
            objectId: 'template.rvt'
        }));

        this.setState({
            form: formData
        })


        fetch('designautomation', {
            method: 'POST',
            body: formData,
            //headers: {
            //    //'Content-Type': 'application/json'
            //    'Content-Type': 'application/x-www-form-urlencoded',
            //},
        })
            .then(response => response.json())
            .then(data => { console.log(data) })
            .catch(error => console.log(error));
    }

并且控制器的代码非常标准,并且根据伪造示例之一进行了轻微修改

[HttpPost]
        [Route("designautomation")]
        public async Task<IActionResult> Test([FromForm] StartWorkitemInput input)
        {

            JObject workItemData = JObject.Parse(input.data);
            double Width = workItemData["Width"].Value<double>();
            double Length = workItemData["Length"].Value<double>();
            double Depth = workItemData["Depth"].Value<double>();
            double Thickness = workItemData["Thickness"].Value<double>();
            double BottomThickness = workItemData["BottomThickness"].Value<double>();
            double rebarSpacing = workItemData["rebarSpacing"].Value<double>();
            string outputrvt = workItemData["outputrvt"].Value<string>();
            string activityId = workItemData["activityId"].Value<string>();
            string bucketId = workItemData["bucketId"].Value<string>();
            string objectId = workItemData["objectId"].Value<string>();

            // basic input validation
            string activityName = string.Format("{0}.{1}", NickName, activityId);
            string bucketKey = bucketId;
            string inputFileNameOSS = objectId;

            // OAuth token
            dynamic oauth = await OAuthController.GetInternalAsync();

            // prepare workitem arguments
            // 1. input file
            dynamic inputJson = new JObject();
            inputJson.Width = Width;
            inputJson.Length = Length;
            inputJson.Depth = Depth;
            inputJson.Thickness = Thickness;
            inputJson.BottomThickness = BottomThickness;
            inputJson.rebarSpacing = rebarSpacing;
            inputJson.outputrvt = outputrvt;

            XrefTreeArgument inputFileArgument = new XrefTreeArgument()
            {
                Url = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/aecom-bucket-demo-library/objects/{0}", objectId),
                Headers = new Dictionary<string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };

            // 2. input json
            XrefTreeArgument inputJsonArgument = new XrefTreeArgument()
            {
                Headers = new Dictionary<string, string>()
                {
                    {"Authorization", "Bearer " + oauth.access_token }
                },
                Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
            };

            // 3. output file
            string outputFileNameOSS = outputrvt;
            XrefTreeArgument outputFileArgument = new XrefTreeArgument()
            {
                Url = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputFileNameOSS),
                Verb = Verb.Put,
                Headers = new Dictionary<string, string>()
                {
                    {"Authorization", "Bearer " + oauth.access_token }
                }
            };

            // prepare & submit workitem
            // the callback contains the connectionId (used to identify the client) and the outputFileName of this workitem
            //string callbackUrl = string.Format("{0}/api/forge/callback/designautomation?id={1}&bucketKey={2}&outputFileName={3}", OAuthController.FORGE_WEBHOOK_URL, browerConnectionId, bucketKey, outputFileNameOSS);
            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = activityName,
                Arguments = new Dictionary<string, IArgument>()
                {
                    { "rvtFile",  inputFileArgument },
                    { "jsonFile",  inputJsonArgument },
                    { "result",  outputFileArgument }
                    ///{ "onComplete", new XrefTreeArgument { Verb = Verb.Post, Url = callbackUrl } }
                }
            };

            DesignAutomationClient client = new DesignAutomationClient();
            client.Service.Client.BaseAddress = new Uri(@"http://localhost:3000");


            WorkItemStatus workItemStatus = await client.CreateWorkItemAsync(workItemSpec);

            return Ok();
        }

知道为什么给我这个错误吗?我已经使用邮递员测试了 api,它工作正常,但是当我尝试从按钮调用它时,我一直收到这个错误。开始调试,似乎 url 写入正确。也许这是我想念的一件非常简单的事情。 干杯!

【问题讨论】:

    标签: autodesk-forge autodesk-designautomation


    【解决方案1】:

    好的解决了... 我错过了在启动中添加服务以及在 appsettings.json 中添加 Forge 连接信息(clientid、clientsecret)

    现在我需要测试 AWS 部署,我想我已经完成了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2022-10-17
      • 1970-01-01
      • 2021-02-02
      • 2022-08-12
      • 2020-12-02
      • 2016-10-24
      相关资源
      最近更新 更多