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

Manage blob properties and metadata with JavaScript

Feedback

In this article

In addition to the data they contain, blobs support system properties and user-defined metadata. This article shows how to manage system properties and user-defined metadata with theAzure Storage client library for JavaScript.

Prerequisites

About properties and metadata

  • System properties: System properties exist on each Blob storage resource. Some of them can be read or set, while others are read-only. Under the covers, some system properties correspond to certain standard HTTP headers. The Azure Storage client library for JavaScript maintains these properties for you.

  • User-defined metadata: User-defined metadata consists of one or more name-value pairs that you specify for a Blob storage resource. You can use metadata to store additional values with the resource. Metadata values are for your own purposes only, and don't affect how the resource behaves.

    Metadata name/value pairs are valid HTTP headers and should adhere to all restrictions governing HTTP headers. For more information about metadata naming requirements, seeMetadata names.

Note

Blob index tags also provide the ability to store arbitrary user-defined key/value attributes alongside an Azure Blob storage resource. While similar to metadata, only blob index tags are automatically indexed and made searchable by the native blob service. Metadata cannot be indexed and queried unless you utilize a separate service such as Azure Search.

To learn more about this feature, seeManage and find data on Azure Blob storage with blob index (preview).

Set and retrieve properties

To set properties on a blob, use the following method:

The following code example sets theblobContentType andblobContentLanguage system properties on a blob.

Any properties not explicitly set are cleared. The following code example first gets the existing properties on the blob, then uses them to populate the headers that aren't being updated.

async function setHTTPHeaders(blobClient, headers) {    // Get existing properties  const properties = await blobClient.getProperties();  // Set the blobContentType and blobContentLanguage headers  // Populate the remaining headers from the existing properties  blobHeaders = {    blobContentType: 'text/plain',    blobContentLanguage: 'en-us',    blobContentEncoding: properties.contentEncoding,    blobCacheControl: properties.cacheControl,    blobContentDisposition: properties.contentDisposition,    blobContentMD5: properties.contentMD5  },  await blobClient.setHTTPHeaders(blobHeaders);}

To retrieve properties on a blob, use the following method:

The following code example gets a blob's system properties and displays some of the values:

async function getProperties(blobClient) {  const properties = await blobClient.getProperties();    console.log(`blobType: ${properties.blobType}`);  console.log(`contentType: ${properties.contentType}`);  console.log(`contentLength: ${properties.contentLength}`);  console.log(`lastModified: ${properties.lastModified}`);}

Set and retrieve metadata

You can specify metadata as one or more name-value pairs on a blob or container resource. To set metadata, send aMetadata object containing name-value pairs using the following method:

The following code example sets metadata on a blob:

async function setBlobMetadata(blobClient, metadata) {    metadata = {    docType: 'text',    category: 'reference'  };  await blobClient.setMetadata(metadata);}

To retrieve metadata, call thegetProperties method on your blob to populate the metadata collection, then read the values from themetadata property. ThegetProperties method retrieves blob properties and metadata by calling both theGet Blob Properties operation and theGet Blob Metadata operation.

Resources

To learn more about how to manage system properties and user-defined metadata 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 managing system properties and user-defined metadata use the following REST API operations:

Client library resources

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?