【问题标题】:Resumable Upload File by Forge SDK, UploadChunkWithHttpInfo failingForge SDK 可恢复上传文件,UploadChunkWithHttpInfo 失败
【发布时间】:2019-04-11 23:05:48
【问题描述】:

我正在尝试使用 SDK for .Net 上传文件,使用此示例: https://forge.autodesk.com/blog/c-resumable-upload-file-forge-sdk

如果我直接使用 REST API,我可以毫无问题地创建存储桶并上传文件,使用不分块的直接上传。 如果我使用 SDK 方法,我总是得到

Message: "An error has occurred."
ExceptionMessage: "Error calling UploadChunk: {"developerMessage":"ACM check failed, user or calling service does not have access to perform this operation","userMessage":"","errorCode":"AUTH-012","more info":"http://developer.api.autodesk.com/documentation/v1/errors/AUTH-012"}"
ExceptionType: "Autodesk.Forge.Client.ApiException"
StackTrace: "   at Autodesk.Forge.ObjectsApi.UploadChunkWithHttpInfo(String bucketKey, String objectName, Nullable`1 contentLength, String contentRange, String sessionId, Stream body, String contentDisposition, String ifMatch)

我已验证存储桶密钥相同。 我正在使用 1.4.0 版本的 SDK,有一个 1.5.1 Alpha 版本可用,我不想使用。

【问题讨论】:

  • 该错误表明您的存储桶密钥不正确。您是否在传递给呼叫之前对其进行了编码?无需这样做,因为 SDK 会为您处理。
  • 没有密钥是正确的,它在使用 REST 调用时有效,而不是 SDK。如果我使用非块上传,我会得到完全相同的错误,即 ObjectsApi.UploadObject。

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


【解决方案1】:

所以我尝试了this codeHttpInfo 选项,如下所示,并且工作正常。根据您的消息,正如@Bryan Huang 所指出的,该错误很可能与身份验证(或临时故障)有关

long chunkSize = 2 * 1024 * 1024; // 2 Mb
long numberOfChunks = (long)Math.Round((double)(fileSize / chunkSize)) + 1;

progressBar.Maximum = (int)numberOfChunks;

long start = 0;
chunkSize = (numberOfChunks > 1 ? chunkSize : fileSize);
long end = chunkSize;
string sessionId = Guid.NewGuid().ToString();

// upload one chunk at a time
using (BinaryReader reader = new BinaryReader(new FileStream(filePath, FileMode.Open)))
{
    for (int chunkIndex = 0; chunkIndex < numberOfChunks; chunkIndex++)
    {
        string range = string.Format("bytes {0}-{1}/{2}", start, end, fileSize);

        long numberOfBytes = chunkSize + 1;
        byte[] fileBytes = new byte[numberOfBytes];
        MemoryStream memoryStream = new MemoryStream(fileBytes);
        reader.BaseStream.Seek((int)start, SeekOrigin.Begin);
        int count = reader.Read(fileBytes, 0, (int)numberOfBytes);
        memoryStream.Write(fileBytes, 0, (int)numberOfBytes);
        memoryStream.Position = 0;

        dynamic chunkUploadResponse = await objects.UploadChunkAsyncWithHttpInfo(bucketKey, objectKey, (int)numberOfBytes, range, sessionId, memoryStream);

        start = end + 1;
        chunkSize = ((start + chunkSize > fileSize) ? fileSize - start - 1 : chunkSize);
        end = start + chunkSize;

        progressBar.CustomText = string.Format("{0} Mb uploaded...", (chunkIndex * chunkSize) / 1024 / 1024);
        progressBar.Value = chunkIndex;
    }
}

【讨论】:

  • 我从您的示例中看到您使用了两条腿身份验证。我使用三足和 A360,所以这个 SDK 调用可能只适用于两足身份验证和 BIM360?当我尝试其他一些存储桶方法时,我注意到它们失败了,并描述它们仅适用于 2-legged auth。
  • 在 BIM360 上遇到同样的错误,但仍然使用 3-legged auth,这在这种情况下不需要
  • 我会检查的
  • Augusto:我的代码基于您在forge.autodesk.com/blog/upload-files-bim-360-c 文章中的示例代码,以及您在forge.autodesk.com/blog/c-resumable-upload-file-forge-sdk 中引用的文件上传。您的文章说它适用于 BIM360,所以我现在已将代码更改为使用两条腿身份验证和 BIM360。您的代码正在使用 projectApi.PostStorageAsync 并从响应中检索 bucketKey。在我的代码中,“urn:adsk.objects:os.object:wip.dm.prod/40e0e6c5-bd92-4d49-90e6-82ea9b083bbe.jpg”,您的代码提取“wip.dm.prod”作为bucketKey。
  • 此 bucketKey 在 REST API 中有效,但在 SDK 中无效!!如果我迭代 BucketsAPI.GetBuckets,我的 bucketKey 是 bjv1ueyw3aaaxjsxkiaxsmnzoxjefykn636755378203905689,即完全不同的格式!这个键在 ObjectsApi 中有效!问题是,我如何确保它们是相同的?到目前为止,我发现 SDK 使用起来更加复杂和令人沮丧,幸运的是我的工作代码仅使用 REST API
猜你喜欢
  • 2018-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-08
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多