Upload large files (2GB) to Autodesk Forge Data Management API

你说的曾经没有我的故事 提交于 2020-04-16 03:23:44

问题


I am trying to upload some models to the Autodesk Forge Data Management API. Unfortunately, the models are 1GB+ in size and the API gives a timeout exception:

StatusCode: 504, ReasonPhrase: 'GATEWAY_TIMEOUT'

Using the following code (C#):

var url = $"https://developer.api.autodesk.com/oss/v2/buckets/{bucketKey}/objects/{objectName}";

        using (var httpClient = GetAuthorizedHttpClient("data:write"))
        {
            httpClient.Timeout = TimeSpan.FromMinutes(120);
            var request = new HttpRequestMessage(HttpMethod.Put, url);

            fileStream.Position = 0;

            request.Content = new StreamContent(fileStream);                

            var response = httpClient.SendAsync(request).Result;

            var responseContent = response.Content.ReadAsStringAsync().Result;

            if (!response.IsSuccessStatusCode)
                throw new Exception($"Failed to upload object: {response.ReasonPhrase}");

            var result = JsonConvert.DeserializeObject<ObjectUploadResult>(response.Content.ReadAsStringAsync().Result);
            return result;
        }

Do you have any suggestions? Thanks in advance!


回答1:


That's expected, you should use resumable upload for files larger than 100Mb (as per documentation).

Check this sample using the Autodesk.Forge .NET package.




回答2:


Cause error 416 when uploading large file with the forge-bucketsmanager-desktop.
Please check this issue.

  • https://github.com/Autodesk-Forge/forge-bucketsmanager-desktop/issues/12


来源:https://stackoverflow.com/questions/52892577/upload-large-files-2gb-to-autodesk-forge-data-management-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!