このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
この記事では、JavaScript 用の Azure Storage クライアント ライブラリを使ってコンテナーを削除する方法について説明します。コンテナーの論理的な削除を有効にしている場合は、削除されたコンテナーを復元できます。
コンテナーを削除するには、BlobServiceClient クラスの次のメソッドを使います。
また、ContainerClient クラスの次のメソッドを使用してコンテナーを削除することもできます。
コンテナーを削除した後、少なくとも 30 秒間は同じ名前のコンテナーを作成することはできません。 同じ名前のコンテナーを作成しようとすると、HTTP エラー コード409 (Conflict)
で失敗します。 コンテナーまたはそれに含まれる BLOB に対して他の操作を実行しようとすると、HTTP エラー コード404 (Not Found)
で失敗します。
次の例では、BlobServiceClient
オブジェクトを使用して、指定したコンテナーを削除しています。
async function deleteContainer(blobServiceClient, containerName) { return await blobServiceClient.deleteContainer(containerName);}
次の例は、指定したプレフィックスで始まるすべてのコンテナーを削除する方法を示しています。
async function deleteContainersWithPrefix(blobServiceClient, prefix) { const containerOptions = { includeDeleted: false, includeMetadata: false, includeSystem: true, prefix } for await (const containerItem of blobServiceClient.listContainers(containerOptions)) { try{ const containerClient = blobServiceClient.getContainerClient(containerItem.name); await containerClient.delete(); console.log(`Deleted ${containerItem.name} container - success`); }catch(ex){ console.log(`Deleted ${containerItem.name} container - failed - ${ex.message}`); } }}
ストレージ アカウントでコンテナーの論理的な削除が有効になっている場合は、コンテナーが削除された後も、指定した保持期間中であればコンテナーとその内容を復旧できます。 論理的に削除されたコンテナーは、BlobServiceClient オブジェクトを使用して復元できます。
次の例では、削除されたコンテナーを検索し、その削除されたコンテナーのバージョン ID を取得した後、その ID をundeleteContainer
メソッドに渡してコンテナーを復元します。
async function undeleteContainer(blobServiceClient, containerName) { // Version to restore let containerVersion; const containerOptions = { includeDeleted: true, prefix: containerName } // Find the deleted container and restore it for await (const containerItem of blobServiceClient.listContainers(containerOptions)) { if (containerItem.name === containerName) { containerVersion = containerItem.version; } } const containerClient = await blobServiceClient.undeleteContainer( containerName, containerVersion, );}
JavaScript 用 Azure Blob Storage クライアント ライブラリを使用したコンテナーの削除の詳細については、次のリソースを参照してください。
Azure SDK for JavaScript には Azure REST API に基づいて構築されたライブラリが含まれるため、使い慣れた JavaScript パラダイムを通じて REST API 操作を利用できます。 コンテナーを削除または復元するためのクライアント ライブラリ メソッドでは、次の REST API 操作が使用されます。
このページはお役に立ちましたか?
このページはお役に立ちましたか?