autodesk-forge - 将文件上传到 BIM 360 Document Management Forge API 时出现问题
问题描述
我在将文件上传到 BIM 360 时遇到问题。遵循https://forge.autodesk.com/en/docs/bim360/v1/tutorials/document-management/upload-document/并且能够做到第 5 步. 但在上传时,状态显示“未找到”。请帮助我了解代码是否有任何问题
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);
}
请帮助
解决方案
我看到您正在通过 RestSharp 和 C# SDK 访问端点。
请尝试forge-viewhubs示例中的方法。
推荐阅读
- postgresql - 对于联接表中不存在的行,如何将空值更新为 0?
- c++ - 如何用未知参数编写排序。无法使用 void*/ 进行迭代
- android - ScrollView 中的 editText 问题被 InputKeyboard 隐藏
- c# - 容量小于计数的 C# 异常
- java - 使用 DynamoDbMapper 从 dynamodb java 中检索所有项目 id
- javascript - 计算光标位置的差异
- python - 在 MacBook Pro 上使用 pybind11
- reactjs - 如何使用打字稿将数组中的对象推入一个对象数组并做出反应?
- php - 文件未在线上传(离线/本地作品)
- javascript - 当用户已登录浏览器时,从 Google 登录按钮触发功能