在 Azure Blob 存储中重命名 blob 文件
没有可以在 Azure 上重命名 blob 文件的 API。此代码段演示了如何在 Microsoft Azure Blob 存储中重命名 blob 文件。
StorageCredentials cred = new StorageCredentials("[Your storage account name]", "[Your storage account key]");
CloudBlobContainer container = new CloudBlobContainer(new Uri("http://[Your storage account name].blob.core.windows.net/[Your container name] /"), cred);
string fileName = "OldFileName";
string newFileName = "NewFileName";
CloudBlockBlob blobCopy = container.GetBlockBlobReference(newFileName);
if (!await blobCopy.ExistsAsync())
{
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
if (await blob.ExistsAsync())
{
await blobCopy.StartCopyAsync(blob);
await blob.DeleteIfExistsAsync();
}
}
有关更多信息,请参阅如何在 Azure Blob 存储中重命名 blob 文件