我正在尝试将 zip 文件上传到 Autodesk Forge 的对象存储服务 (OSS),然后使用它为 Design Automation 创建 AppBundle。当我成功上传文件并创建 AppBundle 时,链接到 AppBundle 的包 URL 在访问时总是给出 NoSuchKey 错误。
这是我的代码的相关部分:
var auth = new TwoLeggedApi();
dynamic tokenResponse = await auth.AuthenticateAsync(
ClientId,
ClientSecret,
oAuthConstants.CLIENT_CREDENTIALS,
[Scope.DataRead, Scope.DataWrite]
);
var objectsApi = new ObjectsApi { Configuration = { AccessToken = tokenResponse.access_token; } };
using var fileStream = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read);
dynamic response = await objectsApi.UploadObjectAsync(
bucketKey,
objectKey,
(int)fileStream.Length,
fileStream,
"application/zip"
);
string ossObjectUrl = $"https://developer.api.autodesk.com/oss/v2/buckets/{bucketKey}/objects/{objectKey}";
string fullyQualifiedId = $"{_account}.{bundleId}";
var newVersion = new AppBundle
{
Id = fullyQualifiedId,
Engine = $"Autodesk.Revit+{yearVersion}",
Package = ossObjectUrl,
Description = $"App bundle for Revit {yearVersion}",
};
AppBundle bundle = await _daClient.CreateAppBundleAsync(newVersion);
// package URL is valid
// after creating an alias and fetching the AppBundle again, the package url is invalid
AppBundle 创建成功,但是当我设置别名并尝试访问包 URL 时,出现错误:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
您无法将 OSS URL 传递给 AppBundle 类中的 Package 属性。此属性需要位于本地磁盘上的包 zip 文件的路径。
var newVersion = new AppBundle
{
Id = fullyQualifiedId,
Engine = $"Autodesk.Revit+{yearVersion}",
Package = @"D:\Temp\package.zip", // Must be a local disk path
Description = $"App bundle for Revit {yearVersion}",
};
https://developer.api.autodesk.com/da/us-east/v3/appbundles
) 创建新的 AppBundle 并获取上传详细信息。
test
)以方便版本管理。private async Task<string> SetupAppBundleAsync()
{
// Log the start of the AppBundle setup process
Console.WriteLine("Setting up AppBundle...");
// Construct the fully qualified AppBundle name
var myApp = $"{_config.Owner}.{_config.BundleName}+{_config.Label}";
// Check if the AppBundle already exists
var appResponse = await _designAutomationClient.AppBundlesApi.GetAppBundleAsync(myApp, throwOnError: false);
// Define the new AppBundle details
var app = new AppBundle
{
Engine = _config.TargetEngine,
Id = _config.BundleName
};
// Validate that the package path is not null
var package = _config.BundlePath ?? throw new NullReferenceException("BundlePath cannot be null.");
if (appResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound)
{
// If the AppBundle doesn't exist, create it
Console.WriteLine($"\tCreating AppBundle {myApp}...");
await _designAutomationClient.CreateAppBundleAsync(app, _config.Label, package);
return myApp;
}
// Ensure the response is successful if the AppBundle exists
await appResponse.HttpResponse.EnsureSuccessStatusCodeAsync();
Console.WriteLine("\tFound existing AppBundle...");
// Check if the existing package matches the new one
if (!await EqualsAsync(package, appResponse.Content.Package))
{
// If the packages differ, update the AppBundle
Console.WriteLine($"\tUpdating AppBundle {myApp}...");
await _designAutomationClient.UpdateAppBundleAsync(app, _config.Label, package);
}
// Return the name of the AppBundle
return myApp;
}
请按照此分步指南获取详细说明: 发布 AppBundle