Package version:
Creates an instance of PageBlobClient.
Account connection string or a SAS connection string of an Azure storage account.
[ Note - Account connection string can only be used in NODE.JS runtime. ]
Account connection string example -
DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net
SAS connection string example -
BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString
Container name.
Blob name.
Optionaloptions: StoragePipelineOptionsOptional. Options to configure the HTTP pipeline.
Creates an instance of PageBlobClient. This method accepts an encoded URL or non-encoded URL pointing to a blob. Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped. If a blob name includes ? or %, blob name must be encoded in the URL.
A Client string pointing to Azure Storage page blob, such as "https://myaccount.blob.core.windows.net/mycontainer/pageblob". You can append a SAS if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net/mycontainer/pageblob?sasString".
Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
Optionaloptions: StoragePipelineOptionsOptional. Options to configure the HTTP pipeline.
Creates an instance of PageBlobClient.
A URL string pointing to Azure Storage page blob, such as "https://myaccount.blob.core.windows.net/mycontainer/pageblob". You can append a SAS if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net/mycontainer/pageblob?sasString". This method accepts an encoded URL or non-encoded URL pointing to a blob. Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped. However, if a blob name includes ? or %, blob name must be encoded in the URL. Such as a blob named "my?blob%", the URL should be "https://myaccount.blob.core.windows.net/mycontainer/my%3Fblob%25".
Call newPipeline() to create a default pipeline, or provide a customized pipeline.
ReadonlyaccountReadonlycredentialSuch as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
Protected ReadonlyisProtected ReadonlystorageStorageClient is a reference to protocol layer operations entry, which is generated by AutoRest generator.
ReadonlyurlEncoded URL string value.
The name of the storage container the blob is associated with.
The name of the blob.
Aborts a pending asynchronous Copy Blob operation, and leaves a destination blob with zero length and full metadata. Version 2012-02-12 and newer.
Id of the Copy From URL operation.
Optional options to the Blob Abort Copy From URL operation.
Asynchronously copies a blob to a destination within the storage account.
This method returns a long running operation poller that allows you to wait
indefinitely until the copy is completed.
You can also cancel a copy before it is completed by calling cancelOperation on the poller.
Note that the onProgress callback will not be invoked if the operation completes in the first
request, and attempting to cancel a completed copy will result in an error being thrown.
In version 2012-02-12 and later, the source for a Copy Blob operation can be a committed blob in any Azure storage account. Beginning with version 2015-02-21, the source for a Copy Blob operation can be an Azure file in any Azure storage account. Only storage accounts created on or after June 7th, 2012 allow the Copy Blob operation to copy from another storage account.
url to the source Azure Blob/File.
Optional options to the Blob Start Copy From URL operation.
https://learn.microsoft.com/rest/api/storageservices/copy-blob
import { BlobServiceClient } from "@azure/storage-blob";
import { DefaultAzureCredential } from "@azure/identity";
const account = "<account>";
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential(),
);
const containerName = "<container name>";
const blobName = "<blob name>";
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
// Example using automatic polling
const automaticCopyPoller = await blobClient.beginCopyFromURL("url");
const automaticResult = await automaticCopyPoller.pollUntilDone();
// Example using manual polling
const manualCopyPoller = await blobClient.beginCopyFromURL("url");
while (!manualCopyPoller.isDone()) {
await manualCopyPoller.poll();
}
const manualResult = manualCopyPoller.getResult();
// Example using progress updates
const progressUpdatesCopyPoller = await blobClient.beginCopyFromURL("url", {
onProgress(state) {
console.log(`Progress: ${state.copyProgress}`);
},
});
const progressUpdatesResult = await progressUpdatesCopyPoller.pollUntilDone();
// Example using a changing polling interval (default 15 seconds)
const pollingIntervalCopyPoller = await blobClient.beginCopyFromURL("url", {
intervalInMs: 1000, // poll blob every 1 second for copy progress
});
const pollingIntervalResult = await pollingIntervalCopyPoller.pollUntilDone();
// Example using copy cancellation:
const cancelCopyPoller = await blobClient.beginCopyFromURL("url");
// cancel operation after starting it.
try {
await cancelCopyPoller.cancelOperation();
// calls to get the result now throw PollerCancelledError
cancelCopyPoller.getResult();
} catch (err: any) {
if (err.name === "PollerCancelledError") {
console.log("The copy was cancelled.");
}
}
Frees the specified pages from the page blob.
Starting byte position of the pages to clear.
Optionalcount: numberNumber of bytes to clear.
Options to the Page Blob Clear Pages operation.
Response data for the Page Blob Clear Pages operation.
Creates a page blob of the specified length. Call uploadPages to upload data data to a page blob.
size of the page blob.
Options to the Page Blob Create operation.
Response data for the Page Blob Create operation.
Creates a page blob of the specified length. Call uploadPages to upload data data to a page blob. If the blob with the same name already exists, the content of the existing blob will remain unchanged.
size of the page blob.
Creates a read-only snapshot of a blob.
Optional options to the Blob Create Snapshot operation.
Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the Delete Blob operation.
Optional options to Blob Delete operation.
Marks the specified blob or snapshot for deletion if it exists. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the Delete Blob operation.
Optional options to Blob Delete operation.
Delete the immutablility policy on the blob.
Optional options to delete immutability policy on the blob.
Reads or downloads a blob from the system, including its metadata and properties. You can also call Get Blob to read a snapshot.
From which position of the blob to download, greater than or equal to 0
Optionalcount: numberHow much data to be downloaded, greater than 0. Will download to the end when undefined
Optional options to Blob Download operation.
Example usage (Node.js):
import { BlobServiceClient } from "@azure/storage-blob";
import { DefaultAzureCredential } from "@azure/identity";
const account = "<account>";
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential(),
);
const containerName = "<container name>";
const blobName = "<blob name>";
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
// Get blob content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody
const downloadBlockBlobResponse = await blobClient.download();
if (downloadBlockBlobResponse.readableStreamBody) {
const downloaded = await streamToString(downloadBlockBlobResponse.readableStreamBody);
console.log(`Downloaded blob content: ${downloaded}`);
}
async function streamToString(stream: NodeJS.ReadableStream): Promise<string> {
const result = await new Promise<Buffer<ArrayBuffer>>((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (data) => {
chunks.push(Buffer.isBuffer(data) ? data : Buffer.from(data));
});
stream.on("end", () => {
resolve(Buffer.concat(chunks));
});
stream.on("error", reject);
});
return result.toString();
}
Example usage (browser):
import { BlobServiceClient } from "@azure/storage-blob";
import { DefaultAzureCredential } from "@azure/identity";
const account = "<account>";
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential(),
);
const containerName = "<container name>";
const blobName = "<blob name>";
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
// Get blob content from position 0 to the end
// In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody
const downloadBlockBlobResponse = await blobClient.download();
const blobBody = await downloadBlockBlobResponse.blobBody;
if (blobBody) {
const downloaded = await blobBody.text();
console.log(`Downloaded blob content: ${downloaded}`);
}
ONLY AVAILABLE IN NODE.JS RUNTIME.
Downloads an Azure Blob in parallel to a buffer. Offset and count are optional, downloads the entire blob if they are not provided.
Warning: Buffers can only support files up to about one gigabyte on 32-bit systems or about two gigabytes on 64-bit systems due to limitations of Node.js/V8. For blobs larger than this size, consider downloadToFile.
Optionaloffset: numberFrom which position of the block blob to download(in bytes)
Optionalcount: numberHow much data(in bytes) to be downloaded. Will download to the end when passing undefined
Optionaloptions: BlobDownloadToBufferOptionsBlobDownloadToBufferOptions
ONLY AVAILABLE IN NODE.JS RUNTIME.
Downloads an Azure Blob in parallel to a buffer. Offset and count are optional, downloads the entire blob if they are not provided.
Warning: Buffers can only support files up to about one gigabyte on 32-bit systems or about two gigabytes on 64-bit systems due to limitations of Node.js/V8. For blobs larger than this size, consider downloadToFile.
Buffer to be fill, must have length larger than count
Optionaloffset: numberFrom which position of the block blob to download(in bytes)
Optionalcount: numberHow much data(in bytes) to be downloaded. Will download to the end when passing undefined
Optionaloptions: BlobDownloadToBufferOptionsBlobDownloadToBufferOptions
ONLY AVAILABLE IN NODE.JS RUNTIME.
Downloads an Azure Blob to a local file. Fails if the the given file path already exits. Offset and count are optional, pass 0 and undefined respectively to download the entire blob.
From which position of the block blob to download.
Optionalcount: numberHow much data to be downloaded. Will download to the end when passing undefined.
Options to Blob download options.
The response data for blob download operation, but with readableStreamBody set to undefined since its content is already read and written into a local file at the specified path.
Returns true if the Azure blob resource represented by this client exists; false otherwise.
NOTE: use this function with care since an existing blob might be deleted by other clients or applications. Vice versa new blobs might be added by other clients or applications after this function completes.
options to Exists operation.
Only available for BlobClient constructed with a shared key credential.
Generates string to sign for a Blob Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.
Optional parameters.
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
Only available for BlobClient constructed with a shared key credential.
Generates a Blob Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.
Optional parameters.
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
Only available for BlobClient constructed with a shared key credential.
Generates string to sign for a Blob Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.
Optional parameters.
Return value of blobServiceClient.getUserDelegationKey()
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
Generates a Blob Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.
Optional parameters.
Return value of blobServiceClient.getUserDelegationKey()
The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
The Get Account Information operation returns the sku name and account kind for the specified account. The Get Account Information operation is available on service versions beginning with version 2018-03-28.
Options to the Service Get Account Info operation.
Response data for the Service Get Account Info operation.
Creates a AppendBlobClient object.
Get a BlobLeaseClient that manages leases on the blob.
OptionalproposeLeaseId: stringInitial proposed lease Id.
A new BlobLeaseClient object for managing leases on the blob.
Creates a BlockBlobClient object.
Creates a PageBlobClient object.
Returns the list of valid page ranges for a page blob or snapshot of a page blob.
Starting byte position of the page ranges.
Optionalcount: numberNumber of bytes to get.
Options to the Page Blob Get Ranges operation.
Response data for the Page Blob Get Ranges operation.
Gets the collection of page ranges that differ between a specified snapshot and this page blob.
Starting byte position of the page blob
Number of bytes to get ranges diff.
Timestamp of snapshot to retrieve the difference.
Options to the Page Blob Get Page Ranges Diff operation.
Response data for the Page Blob Get Page Range Diff operation.
Gets the collection of page ranges that differ between a specified snapshot and this page blob for managed disks.
Starting byte position of the page blob
Number of bytes to get ranges diff.
URL of snapshot to retrieve the difference.
Options to the Page Blob Get Page Ranges Diff operation.
Response data for the Page Blob Get Page Range Diff operation.
Returns all user-defined metadata, standard HTTP properties, and system properties for the blob. It does not return the content of the blob.
Optional options to Get Properties operation.
https://learn.microsoft.com/rest/api/storageservices/get-blob-properties
WARNING: The metadata object returned in the response will have its keys in lowercase, even if
they originally contained uppercase characters. This differs from the metadata keys returned by
the methods of ContainerClient that list blobs using the includeMetadata option, which
will retain their original casing.
Gets the tags associated with the underlying blob.
Returns an async iterable iterator to list of page ranges for a page blob.
Starting byte position of the page ranges.
Optionalcount: numberNumber of bytes to get.
Options to the Page Blob Get Ranges operation.
An asyncIterableIterator that supports paging.
https://learn.microsoft.com/rest/api/storageservices/get-page-ranges
.byPage() returns an async iterable iterator to list of page ranges for a page blob.
import { BlobServiceClient } from "@azure/storage-blob";
import { DefaultAzureCredential } from "@azure/identity";
const account = "<account>";
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential(),
);
const containerName = "<container name>";
const blobName = "<blob name>";
const containerClient = blobServiceClient.getContainerClient(containerName);
const pageBlobClient = containerClient.getPageBlobClient(blobName);
// Example using `for await` syntax
let i = 1;
for await (const pageRange of pageBlobClient.listPageRanges()) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
// Example using `iter.next()` syntax
i = 1;
const iter = pageBlobClient.listPageRanges();
let { value, done } = await iter.next();
while (!done) {
console.log(`Page range ${i++}: ${value.start} - ${value.end}`);
({ value, done } = await iter.next());
}
// Example using `byPage()` syntax
i = 1;
for await (const page of pageBlobClient.listPageRanges().byPage({ maxPageSize: 20 })) {
for (const pageRange of page.pageRange || []) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
// Example using paging with a marker
i = 1;
let iterator = pageBlobClient.listPageRanges().byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;
// Prints 2 page ranges
if (response.pageRange) {
for (const pageRange of response.pageRange) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
// Gets next marker
let marker = response.continuationToken;
// Passing next marker as continuationToken
iterator = pageBlobClient.listPageRanges().byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;
// Prints 10 page ranges
if (response.pageRange) {
for (const pageRange of response.pageRange) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
Returns an async iterable iterator to list of page ranges that differ between a specified snapshot and this page blob.
Starting byte position of the page ranges.
Number of bytes to get.
Timestamp of snapshot to retrieve the difference.
Options to the Page Blob Get Ranges operation.
An asyncIterableIterator that supports paging.
https://learn.microsoft.com/rest/api/storageservices/get-page-ranges
.byPage() returns an async iterable iterator to list of page ranges that differ between a specified snapshot and this page blob.
import { BlobServiceClient } from "@azure/storage-blob";
import { DefaultAzureCredential } from "@azure/identity";
const account = "<account>";
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
new DefaultAzureCredential(),
);
const containerName = "<container name>";
const blobName = "<blob name>";
const containerClient = blobServiceClient.getContainerClient(containerName);
const pageBlobClient = containerClient.getPageBlobClient(blobName);
const offset = 0;
const count = 1024;
const previousSnapshot = "<previous snapshot>";
// Example using `for await` syntax
let i = 1;
for await (const pageRange of pageBlobClient.listPageRangesDiff(offset, count, previousSnapshot)) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
// Example using `iter.next()` syntax
i = 1;
const iter = pageBlobClient.listPageRangesDiff(offset, count, previousSnapshot);
let { value, done } = await iter.next();
while (!done) {
console.log(`Page range ${i++}: ${value.start} - ${value.end}`);
({ value, done } = await iter.next());
}
// Example using `byPage()` syntax
i = 1;
for await (const page of pageBlobClient
.listPageRangesDiff(offset, count, previousSnapshot)
.byPage({ maxPageSize: 20 })) {
for (const pageRange of page.pageRange || []) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
// Example using paging with a marker
i = 1;
let iterator = pageBlobClient
.listPageRangesDiff(offset, count, previousSnapshot)
.byPage({ maxPageSize: 2 });
let response = (await iterator.next()).value;
// Prints 2 page ranges
if (response.pageRange) {
for (const pageRange of response.pageRange) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
// Gets next marker
let marker = response.continuationToken;
// Passing next marker as continuationToken
iterator = pageBlobClient
.listPageRangesDiff(offset, count, previousSnapshot)
.byPage({ continuationToken: marker, maxPageSize: 10 });
response = (await iterator.next()).value;
// Prints 10 page ranges
if (response.pageRange) {
for (const pageRange of response.pageRange) {
console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
}
}
Resizes the page blob to the specified size (which must be a multiple of 512).
Target size
Options to the Page Blob Resize operation.
Response data for the Page Blob Resize operation.
Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account and on a block blob in a blob storage account (locally redundant storage only). A premium page blob's tier determines the allowed size, IOPS, and bandwidth of the blob. A block blob's tier determines Hot/Cool/Archive storage type. This operation does not update the blob's ETag.
The tier to be set on the blob. Valid values are Hot, Cool, or Archive.
Optional options to the Blob Set Tier operation.
Sets system properties on the blob.
If no value provided, or no value provided for the specified blob HTTP headers, these blob HTTP headers without a value will be cleared.
OptionalblobHTTPHeaders: BlobHTTPHeadersIf no value provided, or no value provided for
the specified blob HTTP headers, these blob HTTP
headers without a value will be cleared.
A common header to set is blobContentType
enabling the browser to provide functionality
based on file type.
Optional options to Blob Set HTTP Headers operation.
Set immutability policy on the blob.
Optional options to set immutability policy on the blob.
Set legal hold on the blob.
Optional options to set legal hold on the blob.
Sets user-defined metadata for the specified blob as one or more name-value pairs.
If no option provided, or no metadata defined in the parameter, the blob metadata will be removed.
Optionalmetadata: MetadataReplace existing metadata with this value. If no value provided the existing metadata will be removed.
Optional options to Set Metadata operation.
Sets tags on the underlying blob. A blob can have up to 10 tags. Tag keys must be between 1 and 128 characters. Tag values must be between 0 and 256 characters. Valid tag key and value characters include lower and upper case letters, digits (0-9), space (' '), plus ('+'), minus ('-'), period ('.'), foward slash ('/'), colon (':'), equals ('='), and underscore ('_').
Begins an operation to start an incremental copy from one page blob's snapshot to this page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual.
Specifies the name of the source page blob snapshot. For example,
https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=
Options to the Page Blob Copy Incremental operation.
Response data for the Page Blob Copy Incremental operation.
The synchronous Copy From URL operation copies a blob or an internet resource to a new blob. It will not return a response until the copy is complete.
The source URL to copy from, Shared Access Signature(SAS) maybe needed for authentication
Restores the contents and metadata of soft deleted blob and any associated soft deleted snapshots. Undelete Blob is supported only on version 2017-07-29 or later.
Optional options to Blob Undelete operation.
Sets a page blob's sequence number.
Indicates how the service should modify the blob's sequence number.
OptionalsequenceNumber: numberRequired if sequenceNumberAction is max or update
Options to the Page Blob Update Sequence Number operation.
Response data for the Page Blob Update Sequence Number operation.
Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512.
Data to upload
Offset of destination page blob
Content length of the body, also number of bytes to be uploaded
Options to the Page Blob Upload Pages operation.
Response data for the Page Blob Upload Pages operation.
The Upload Pages operation writes a range of pages to a page blob where the contents are read from a URL.
Specify a URL to the copy source, Shared Access Signature(SAS) maybe needed for authentication
The source offset to copy from. Pass 0 to copy from the beginning of source page blob
Offset of destination page blob
Number of bytes to be uploaded from source page blob
Creates a new PageBlobClient object identical to the source but with the specified snapshot timestamp. Provide "" will remove the snapshot and return a Client to the base blob.
The snapshot timestamp.
A new PageBlobClient object identical to the source but with the specified snapshot timestamp.
Creates a new BlobClient object pointing to a version of this blob. Provide "" will remove the versionId and return a Client to the base blob.
The versionId.
A new BlobClient object pointing to the version of this blob.
PageBlobClient defines a set of operations applicable to page blobs.