在 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 檔案