0

我正在学习 Forge 平台。我目前正在使用 Kean Walmsley 编写的示例 (Jigsawify),因为它最准确地描述了我的目标。我遇到了将文件从 Azure 存储帐户下载到 Forge 的问题。我收到的错误是“其中一个 HTTP 标头的值格式不正确。” 我的问题是,在这种情况下,在代码中编写工作项时,有人如何对 HTTP 协议进行故障排除?我可以设置一个断点来查看工作项,但我不够精通,无法理解 HTTP 标头中的缺陷在哪里,甚至在哪里可以找到它。我应该查看工作项的特定属性吗?如果我能找到 HTTP 语句,我可以测试它,但我找不到我应该在哪里找到它。

还是我完全不在基地?

无论如何,这是代码。这是基恩所写内容的修改版:

static void SubmitWorkItem(Activity activity)
    {
      Console.WriteLine("Submitting workitem...");

            CloudStorageAccount storageAccount =
                    CloudStorageAccount.Parse(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));
        StorageCredentials crd = storageAccount.Credentials;

        CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
        CloudFileShare ShareRef = fileClient.GetShareReference("000scrub");
        CloudFileDirectory rootDir = ShareRef.GetRootDirectoryReference();
        CloudFile Fileshare = rootDir.GetFileReference("3359fort.dwg");


    // Create a workitem

    var wi = new WorkItem()
    {
        Id = "", // Must be set to empty
        Arguments = new Arguments(),
        ActivityId = activity.Id
    };


    if (Fileshare.Exists())
    {
        wi.Arguments.InputArguments.Add(new Argument()
        {
            Name = "HostDwg", // Must match the input parameter in activity
            Resource = Fileshare.Uri.ToString(),
            StorageProvider = StorageProvider.Generic // Generic HTTP download (vs A360)
        });
    }

    wi.Arguments.OutputArguments.Add(new Argument()

    {
        Name = "Results", // Must match the output parameter in activity
        StorageProvider = StorageProvider.Generic, // Generic HTTP upload (vs A360)
        HttpVerb = HttpVerbType.POST, // Use HTTP POST when delivering result
        Resource = null, // Use storage provided by AutoCAD.IO
        ResourceKind = ResourceKind.ZipPackage // Upload as zip to output dir

    });

      container.AddToWorkItems(wi);
      container.SaveChanges();

      // Polling loop

      do
      {
        Console.WriteLine("Sleeping for 2 sec...");
        System.Threading.Thread.Sleep(2000);
        container.LoadProperty(wi, "Status"); // HTTP request is made here
        Console.WriteLine("WorkItem status: {0}", wi.Status);
      }
      while (
        wi.Status == ExecutionStatus.Pending ||
        wi.Status == ExecutionStatus.InProgress
      );

      // Re-query the service so that we can look at the details provided
      // by the service

      container.MergeOption =
        Microsoft.OData.Client.MergeOption.OverwriteChanges;
      wi = container.WorkItems.ByKey(wi.Id).GetValue();

      // Resource property of the output argument "Results" will have
      // the output url

      var url =
        wi.Arguments.OutputArguments.First(
          a => a.Name == "Results"
        ).Resource;

      if (url != null)
        DownloadToDocs(url, "SGA.zip");

      // Download the status report

      url = wi.StatusDetails.Report;

      if (url != null)
        DownloadToDocs(url, "SGA-Report.txt");
    }

任何帮助表示赞赏,查克

4

2 回答 2

0

Azure 要求您在上传到预签名 URL 时指定 x-ms-blob-type 标头。请参阅https://github.com/Autodesk-Forge/design.automation-.net-input.output.sample/blob/master/Program.cs#L167

于 2019-03-19T00:17:57.757 回答
0

因此,我能够使用 Albert 提出的迁移到 blob 服务的建议,弄清楚如何将我的文件从 Azure 下载到 Forge。这是代码:

static void SubmitWorkItem(Activity activity)
    {
        Console.WriteLine("Submitting workitem...");

        CloudStorageAccount storageAccount =
            CloudStorageAccount.Parse(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));

        CloudBlobClient BlobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer cloudBlobContainer = BlobClient.GetContainerReference("000scrub");
        CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference("3359fort.dwg");

            // Create a workitem

            var wi = new WorkItem()
    {
        Id = "", // Must be set to empty
        Arguments = new Arguments(),
        ActivityId = activity.Id
    };


    if (blockBlob.Exists())
    {
        wi.Arguments.InputArguments.Add(new Argument()
        {
            Name = "HostDwg", // Must match the input parameter in activity
            Resource = blockBlob.Uri.ToString(),
            StorageProvider = StorageProvider.Generic, // Generic HTTP download (vs A360)
            Headers = new System.Collections.ObjectModel.ObservableCollection<Header>()
                {
                    new Header() { Name = "x-ms-blob-type", Value = "BlockBlob" } // This is required for Azure.
                }

        });
    }

    wi.Arguments.OutputArguments.Add(new Argument()

    {
        Name = "Results", // Must match the output parameter in activity
        StorageProvider = StorageProvider.Generic, // Generic HTTP upload (vs A360)
        HttpVerb = HttpVerbType.POST, // Use HTTP POST when delivering result
        Resource = null, // Use storage provided by AutoCAD.IO
        ResourceKind = ResourceKind.ZipPackage, // Upload as zip to output dir 

    });

      container.AddToWorkItems(wi);
      container.SaveChanges();

      // Polling loop

      do
      {
        Console.WriteLine("Sleeping for 2 sec...");
        System.Threading.Thread.Sleep(2000);
        container.LoadProperty(wi, "Status"); // HTTP request is made here
        Console.WriteLine("WorkItem status: {0}", wi.Status);
      }
      while (
        wi.Status == ExecutionStatus.Pending ||
        wi.Status == ExecutionStatus.InProgress
      );

      // Re-query the service so that we can look at the details provided
      // by the service

      container.MergeOption =
        Microsoft.OData.Client.MergeOption.OverwriteChanges;
      wi = container.WorkItems.ByKey(wi.Id).GetValue();

      // Resource property of the output argument "Results" will have
      // the output url

      var url =
        wi.Arguments.OutputArguments.First(
          a => a.Name == "Results"
        ).Resource;

      if (url != null)
        DownloadToDocs(url, "SGA.zip");

      // Download the status report

      url = wi.StatusDetails.Report;

      if (url != null)
        DownloadToDocs(url, "SGA-Report.txt");
    }

不完整的是结果部分。ZIP 里面什么都没有,但是,嘿,宝贝步骤对吗?

谢谢阿尔伯特。-查克

于 2019-03-19T20:38:32.303 回答