Azure存储: Enable blob versioning on storage account programmatically

标签 azure azure-storage azure-blob-storage azure-sdk-.net

我正在通过 StorageManagementClient 以编程方式创建多个存储帐户,并希望在创建帐户时在帐户级别启用 Blob 版本控制。这是如何实现的?

var storageManagementClient = new StorageManagementClient(azureCredentials)
{
     SubscriptionId = subscriptionId
};
var storageAccountCreateParameters = new StorageAccountCreateParameters
{
     // set properties
};

await storageManagementClient.StorageAccounts.CreateAsync(resourceGroupName, accountName, storageAccountCreateParameters);

我认为这可以作为 StorageAccountCreateParameters 中的创建参数使用,但我在那里没有看到任何内容。

另请参阅https://learn.microsoft.com/en-us/azure/storage/blobs/versioning-enable?tabs=portal

最佳答案

blob 版本控制未包含在StorageAccountCreateParameters中。它属于BlobServiceProperties类。

因此,在使用上面的代码创建存储帐户后,您可以使用以下代码来设置blob版本控制:

var p1 = new BlobServiceProperties()
{
    IsVersioningEnabled = true             
};

storageManagementClient.BlobServices.SetServiceProperties("resource_group", "account_name", p1);

关于Azure存储: Enable blob versioning on storage account programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65605484/

相关文章:

python - 如何在Python中通过URL下载Azure Blob存储文件?

javascript - 返回时 Microsoft.Azure.WebJobs.Script : Unable to cast object of type 'System.String' to type 'Microsoft.AspNetCore.Http.HttpRequest' .

c# - OWIN 登录性能缓慢 >30 秒

azure-storage - 使用 Windows Azure Blob 存储中的子目录

powershell - 自动化 Runbook 中的 Start-AzureStorageBlobCopy 错误

azure - 对 Azure 静态 Web 应用进行更深入的分析?

Django Azure 上传文件到 blob 存储

node.js - 哈希与 Azure Blob 存储不匹配(完整性检查失败)

azure-storage - 本地 VHD/ISO 到 Azure Blob 存储

azure - 将数据从外部源放入 Azure Blob 存储