简体   繁体   English

将文件上传到 BIM 360 Document Management Forge API 时出现问题

[英]Issues While uploading files to BIM 360 Document Management Forge API

I am facing issue while uploading the files to BIM 360. was following https://forge.autodesk.com/en/docs/bim360/v1/tutorials/document-management/upload-document/ and was able to do till step 5. but while uploading, status was showing "Not found".我在将文件上传到 BIM 360 时遇到问题。遵循https://forge.autodesk.com/en/docs/bim360/v1/tutorials/document-management/upload-document/并且能够做到第 5 步. 但在上传时,状态显示“未找到”。 please help me to understand if any issue with code请帮助我了解代码是否有任何问题

    public async void uploadfile(string projectUrl,string projectName)
    {
        string[] idParams = projectUrl.Split('/');
        string projectId = idParams[idParams.Length - 1];
        Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);
        ProjectsApi projectsApi = new ProjectsApi();
        projectsApi.Configuration.AccessToken = credentials.TokenInternal;
        var href = "";
        var folders = await projectsApi.GetProjectTopFoldersAsync(hubId, projectId);
        foreach (KeyValuePair<string, dynamic> folder in new DynamicDictionaryItems(folders.data))
        {
            if (folder.Value.attributes.displayName == "Project Files")
                href = folder.Value.links.self.href;
        }
        BaseAttributesExtensionObject baseAttributesExtensionObject = new BaseAttributesExtensionObject("folders", "1.0.0");
        CreateStorageDataAttributes createStorageDataAttributes = new CreateStorageDataAttributes("html-string.pdf", baseAttributesExtensionObject);
        StorageRelationshipsTargetData storageRelationshipsTargetData = new StorageRelationshipsTargetData(0, href.Split('/')[href.Split('/').Length - 1]);
        CreateStorageDataRelationshipsTarget createStorageDataRelationshipTarget = new CreateStorageDataRelationshipsTarget(storageRelationshipsTargetData);
        CreateStorageDataRelationships createStorageDataRelationships = new CreateStorageDataRelationships(createStorageDataRelationshipTarget);
        CreateStorageData stroragebodydata = new CreateStorageData(0, createStorageDataAttributes, createStorageDataRelationships);
        JsonApiVersionJsonapi jsonApiVersionJsonapi = new JsonApiVersionJsonapi(0);
        CreateStorage storagebody = new CreateStorage(jsonApiVersionJsonapi, stroragebodydata);
        var storageCreated = await projectsApi.PostStorageAsync(projectId, storagebody);
        string[] storageIdParams = ((string)storageCreated.data.id).Split('/');
        string[] bucketKeyParams = storageIdParams[storageIdParams.Length - 2].Split(':');
        string bucketKey = bucketKeyParams[bucketKeyParams.Length - 1];
        string objectName = storageIdParams[storageIdParams.Length - 1];
        string uploadUrl = string.Format("/oss/v2/buckets/{0}/objects/{1}", bucketKey, objectName);
        string s = Convert.ToString(2 * 1024 * 1024);
        RestClient client = new RestClient(BASE_URL);
        RestRequest request = new RestRequest(uploadUrl, RestSharp.Method.POST);
        request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);
        request.AddHeader("Content-Length", s);
        request.AddXmlBody(@"C:\Users\INRM01777\Desktop\Bim360ArchieveTool\Bim360ArchieveTool\html-string.pdf");
        return await client.ExecuteAsync(request);
    }

Kindly help请帮助

I see you're accessing the endpoints through RestSharp and C# SDK.我看到您正在通过 RestSharp 和 C# SDK 访问端点。
Please try the approach from the forge-viewhubs sample.请尝试forge-viewhubs示例中的方法。

You can find there the pieces of code for dealing specifically with the storage and complete upload , considering also the upload in chunks for large files.您可以在那里找到专门处理存储完整上传的代码片段,同时考虑大文件的块上传。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM