Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Delete and restore a blob with JavaScript or TypeScript

Feedback

In this article

This article shows how to delete blobs with theAzure Storage client library for JavaScript, and how to restoresoft-deleted blobs during the retention period.

Prerequisites

  • The examples in this article assume you already have a project set up to work with the Azure Blob Storage client library for JavaScript. To learn about setting up your project, including package installation, importing modules, and creating an authorized client object to work with data resources, seeGet started with Azure Blob Storage and JavaScript.
  • Theauthorization mechanism must have permissions to delete a blob, or to restore a soft-deleted blob. To learn more, see the authorization guidance for the following REST API operations:

Delete a blob

Note

When blob soft delete is enabled for a storage account, you can't perform a permanent deletion using client library methods. Using the methods in this article, a soft-deleted blob, blob version, or snapshot remains available until the retention period expires, at which time it's permanently deleted. To learn more about the underlying REST API operation, seeDelete Blob (REST API).

To delete a blob, call one of the following methods:

If the blob has any associated snapshots, you must delete all of its snapshots to delete the blob. The following code example shows how to delete a blob and its snapshots:

async function deleteBlob(containerClient, blobName){  // include: Delete the base blob and all of its snapshots  // only: Delete only the blob's snapshots and not the blob itself  const options = {    deleteSnapshots: 'include'  }  // Create blob client from container client  const blockBlobClient = containerClient.getBlockBlobClient(blobName);  await blockBlobClient.delete(options);}

Restore a deleted blob

Blob soft delete protects an individual blob and its versions, snapshots, and metadata from accidental deletes or overwrites by maintaining the deleted data in the system for a specified period of time. During the retention period, you can restore the blob to its state at deletion. After the retention period expires, the blob is permanently deleted. For more information about blob soft delete, seeSoft delete for blobs.

You can use the Azure Storage client libraries to restore a soft-deleted blob or snapshot.

Restore soft-deleted objects when versioning is disabled

To restore soft-deleted blobs, call the following method:

This method restores soft-deleted blobs and any deleted snapshots associated with it. Calling this method for a blob that hasn't been deleted has no effect.

async function undeleteBlob(containerClient, blobName){  // Create blob client from container client  const blockBlobClient = containerClient.getBlockBlobClient(blobName);  await blockBlobClient.undelete();}

Resources

To learn more about how to delete blobs and restore deleted blobs using the Azure Blob Storage client library for JavaScript, see the following resources.

Code samples

REST API operations

The Azure SDK for JavaScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar JavaScript paradigms. The client library methods for deleting blobs and restoring deleted blobs use the following REST API operations:

Client library resources

See also

Related content

  • This article is part of the Blob Storage developer guide for JavaScript/TypeScript. To learn more, see the full list of developer guide articles atBuild your JavaScript/TypeScript app.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?