0

我正在尝试使用 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 版本可用,我不想使用它。

4

1 回答 1

0

所以我用这个选项尝试了这段代码HttpInfo,如下所示,并且工作正常。根据您的消息,正如@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;
    }
}
于 2018-11-09T15:56:53.073 回答