【问题标题】:Downloading dwg to Forge将 dwg 下载到 Forge
【发布时间】:2019-08-09 08:42:21
【问题描述】:

我正在学习 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");
    }

任何帮助表示赞赏, 查克

【问题讨论】:

    标签: autodesk-forge autodesk-designautomation


    【解决方案1】:

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

    【讨论】:

    • 这是否意味着 Blob 是我可以使用的唯一文件存储类型?我尝试使用标准 SMB 3.0 协议进行文件存储。
    • 所以回答我自己的问题,是的,我相信您可以使用标准的 SMB 3.0 文件存储,但默认情况下它是私有的,其中 blob 默认是公共的。如果这不正确,请有人告诉我。无论如何,使用 blob 会更容易。
    • 所以这次我试图引用我创建的网站上公共文件夹中的 dwg 文件。我可以直接使用 Google 或 Postman 来解决这个问题,但我的 Workitem 总是 404,在结果文件中有一条失败的下载消息。 XrefTreeArgument 中的文件路径(“InputDwg”)是一个简单的 URL 字符串吗?我错过了什么?
    【解决方案2】:

    因此,我能够根据 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 中没有任何内容,但是,嘿,小步吧?

    谢谢艾伯特。 -查克

    【讨论】:

      猜你喜欢
      • 2018-12-12
      • 2021-12-26
      • 2020-07-22
      • 2021-11-04
      • 2017-06-30
      • 2020-12-15
      • 1970-01-01
      • 2019-12-23
      • 2020-03-09
      相关资源
      最近更新 更多