in sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs [385:908]
public virtual Response<BlobContentInfo> Create(
long size,
PageBlobCreateOptions options,
CancellationToken cancellationToken = default) =>
CreateInternal(
size,
options?.SequenceNumber,
options?.HttpHeaders,
options?.Metadata,
options?.Tags,
options?.Conditions,
options?.ImmutabilityPolicy,
options?.LegalHold,
options?.PremiumPageBlobAccessTier,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="CreateAsync(long, PageBlobCreateOptions, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>.
/// The content of any existing blob is overwritten with the newly initialized page blob
/// To add content to the page blob, call the
/// <see cref="UploadPages(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="options">
/// Optional parameters.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlobContentInfo}"/> describing the
/// newly created page blob.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
public virtual async Task<Response<BlobContentInfo>> CreateAsync(
long size,
PageBlobCreateOptions options,
CancellationToken cancellationToken = default) =>
await CreateInternal(
size,
options?.SequenceNumber,
options?.HttpHeaders,
options?.Metadata,
options?.Tags,
options?.Conditions,
options?.ImmutabilityPolicy,
options?.LegalHold,
options?.PremiumPageBlobAccessTier,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="Create(long, long?, BlobHttpHeaders, Metadata, PageBlobRequestConditions, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. The content of any
/// existing blob is overwritten with the newly initialized page blob
/// To add content to the page blob, call the
/// <see cref="UploadPages(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="sequenceNumber">
/// Optional user-controlled value that you can use to track requests.
/// The value of the <paramref name="sequenceNumber"/> must be between
/// 0 and 2^63 - 1. The default value is 0.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the
/// new page blob.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for this page blob.
/// </param>
/// <param name="conditions">
/// Optional <see cref="PageBlobRequestConditions"/> to add
/// conditions on the creation of this new page blob.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlobContentInfo}"/> describing the
/// newly created page blob.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Response<BlobContentInfo> Create(
long size,
long? sequenceNumber = default,
BlobHttpHeaders httpHeaders = default,
Metadata metadata = default,
PageBlobRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
CreateInternal(
size: size,
sequenceNumber: sequenceNumber,
httpHeaders: httpHeaders,
metadata: metadata,
tags: default,
conditions: conditions,
immutabilityPolicy: default,
legalHold: default,
premiumPageBlobAccessTier: default,
async: false,
cancellationToken: cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="CreateAsync(long, long?, BlobHttpHeaders, Metadata, PageBlobRequestConditions, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. The content of any
/// existing blob is overwritten with the newly initialized page blob
/// To add content to the page blob, call the
/// <see cref="UploadPagesAsync(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="sequenceNumber">
/// Optional user-controlled value that you can use to track requests.
/// The value of the <paramref name="sequenceNumber"/> must be between
/// 0 and 2^63 - 1. The default value is 0.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the
/// new page blob.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for this page blob.
/// </param>
/// <param name="conditions">
/// Optional <see cref="PageBlobRequestConditions"/> to add
/// conditions on the creation of this new page blob.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlobContentInfo}"/> describing the
/// newly created page blob.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<Response<BlobContentInfo>> CreateAsync(
long size,
long? sequenceNumber = default,
BlobHttpHeaders httpHeaders = default,
Metadata metadata = default,
PageBlobRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
await CreateInternal(
size: size,
sequenceNumber: sequenceNumber,
httpHeaders: httpHeaders,
metadata: metadata,
tags: default,
conditions: conditions,
immutabilityPolicy: default,
legalHold: default,
premiumPageBlobAccessTier: default,
async: true,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="CreateIfNotExists(long, PageBlobCreateOptions, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. If the blob already
/// exists, the content of the existing blob will remain unchanged. If the blob does not already exists,
/// a new page blob with the specified <paramref name="size"/> will be created.
/// <see cref="UploadPages(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="options">
/// Optional parameters.
/// </param>
/// /// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// If the page blob does not already exist, A <see cref="Response{BlobContentInfo}"/>
/// describing the newly created page blob. Otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
public virtual Response<BlobContentInfo> CreateIfNotExists(
long size,
PageBlobCreateOptions options,
CancellationToken cancellationToken = default) =>
CreateIfNotExistsInternal(
size,
options?.SequenceNumber,
options?.HttpHeaders,
options?.Metadata,
options?.Tags,
options?.ImmutabilityPolicy,
options?.LegalHold,
options?.PremiumPageBlobAccessTier,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="CreateIfNotExistsAsync(long, PageBlobCreateOptions, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. If the blob already
/// exists, the content of the existing blob will remain unchanged. If the blob does not already exists,
/// a new page blob with the specified <paramref name="size"/> will be created.
/// <see cref="UploadPages(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="options">
/// Optional parameters.
/// </param>
/// /// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// If the page blob does not already exist, A <see cref="Response{BlobContentInfo}"/>
/// describing the newly created page blob. Otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
public virtual async Task<Response<BlobContentInfo>> CreateIfNotExistsAsync(
long size,
PageBlobCreateOptions options,
CancellationToken cancellationToken = default) =>
await CreateIfNotExistsInternal(
size,
options?.SequenceNumber,
options?.HttpHeaders,
options?.Metadata,
options?.Tags,
options?.ImmutabilityPolicy,
options?.LegalHold,
options?.PremiumPageBlobAccessTier,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="CreateIfNotExists(long, long?, BlobHttpHeaders, Metadata, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. If the blob already
/// exists, the content of the existing blob will remain unchanged. If the blob does not already exists,
/// a new page blob with the specified <paramref name="size"/> will be created.
/// <see cref="UploadPages(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="sequenceNumber">
/// Optional user-controlled value that you can use to track requests.
/// The value of the <paramref name="sequenceNumber"/> must be between
/// 0 and 2^63 - 1. The default value is 0.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the
/// new page blob.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for this page blob.
/// </param>
/// /// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// If the page blob does not already exist, A <see cref="Response{BlobContentInfo}"/>
/// describing the newly created page blob. Otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Response<BlobContentInfo> CreateIfNotExists(
long size,
long? sequenceNumber = default,
BlobHttpHeaders httpHeaders = default,
Metadata metadata = default,
CancellationToken cancellationToken = default) =>
CreateIfNotExistsInternal(
size: size,
sequenceNumber: sequenceNumber,
httpHeaders: httpHeaders,
metadata: metadata,
tags: default,
immutabilityPolicy: default,
legalHold: default,
premiumPageBlobAccessTier: default,
async: false,
cancellationToken: cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="CreateIfNotExistsAsync(long, long?, BlobHttpHeaders, Metadata, CancellationToken)"/>
/// operation creates a new page blob of the specified <paramref name="size"/>. If the blob already exists,
/// the content of the existing blob will remain unchanged. If the blob does not already exists,
/// a new page blob with the specified <paramref name="size"/> will be created.
/// <see cref="UploadPagesAsync(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="sequenceNumber">
/// Optional user-controlled value that you can use to track requests.
/// The value of the <paramref name="sequenceNumber"/> must be between
/// 0 and 2^63 - 1. The default value is 0.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the
/// new page blob.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for this page blob.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// If the page blob does not already exist, A <see cref="Response{BlobContentInfo}"/>
/// describing the newly created page blob. Otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<Response<BlobContentInfo>> CreateIfNotExistsAsync(
long size,
long? sequenceNumber = default,
BlobHttpHeaders httpHeaders = default,
Metadata metadata = default,
CancellationToken cancellationToken = default) =>
await CreateIfNotExistsInternal(
size: size,
sequenceNumber: sequenceNumber,
httpHeaders: httpHeaders,
metadata: metadata,
tags: default,
immutabilityPolicy: default,
legalHold: default,
premiumPageBlobAccessTier: default,
async: true,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="CreateIfNotExistsInternal"/> operation creates a new page blob
/// of the specified <paramref name="size"/>. If the blob already exists, the content of
/// the existing blob will remain unchanged. If the blob does not already exists,
/// a new page blob with the specified <paramref name="size"/> will be created.
/// To add content to the page blob, call the
/// <see cref="UploadPagesAsync(Stream, long, byte[], PageBlobRequestConditions, IProgress{long}, CancellationToken)"/> operation.
///
/// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
/// </summary>
/// <param name="size">
/// Specifies the maximum size for the page blob, up to 8 TB. The
/// size must be aligned to a 512-byte boundary.
/// </param>
/// <param name="sequenceNumber">
/// Optional user-controlled value that you can use to track requests.
/// The value of the <paramref name="sequenceNumber"/> must be between
/// 0 and 2^63 - 1. The default value is 0.
/// </param>
/// <param name="httpHeaders">
/// Optional standard HTTP header properties that can be set for the
/// new page blob.
/// </param>
/// <param name="metadata">
/// Optional custom metadata to set for this page blob.
/// </param>
/// <param name="tags">
/// Optional tags to set for this page blob.
/// </param>
/// <param name="immutabilityPolicy">
/// Optional <see cref="BlobImmutabilityPolicy"/> to set on the blob.
/// Note that is parameter is only applicable to a blob within a container that
/// has immutable storage with versioning enabled.
/// </param>
/// <param name="legalHold">
/// Optional. Indicates if a legal hold should be placed on the blob.
/// Note that is parameter is only applicable to a blob within a container that
/// has immutable storage with versioning enabled.
/// </param>
/// <param name="premiumPageBlobAccessTier">
/// Optional. Sets the page blob tiers on the blob.
/// This is only supported for page blobs on premium accounts.
/// </param>
/// <param name="async">
/// Whether to invoke the operation asynchronously.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// If the page blob does not already exist, A <see cref="Response{BlobContentInfo}"/>
/// describing the newly created page blob. Otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
/// containing each failure instance.
/// </remarks>
private async Task<Response<BlobContentInfo>> CreateIfNotExistsInternal(
long size,
long? sequenceNumber,
BlobHttpHeaders httpHeaders,
Metadata metadata,
Tags tags,
BlobImmutabilityPolicy immutabilityPolicy,
bool? legalHold,
PremiumPageBlobAccessTier? premiumPageBlobAccessTier,
bool async,
CancellationToken cancellationToken)
{
using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(PageBlobClient)))
{
ClientConfiguration.Pipeline.LogMethodEnter(
nameof(PageBlobClient),
message:
$"{nameof(Uri)}: {Uri}\n" +
$"{nameof(size)}: {size}\n" +
$"{nameof(sequenceNumber)}: {sequenceNumber}\n" +
$"{nameof(httpHeaders)}: {httpHeaders}");
PageBlobRequestConditions conditions = new PageBlobRequestConditions { IfNoneMatch = new ETag(Constants.Wildcard) };
try
{
return await CreateInternal(
size,
sequenceNumber,
httpHeaders,
metadata,
tags,
conditions,
immutabilityPolicy,
legalHold,
premiumPageBlobAccessTier,
async,
cancellationToken,
$"{nameof(PageBlobClient)}.{nameof(CreateIfNotExists)}")
.ConfigureAwait(false);
}
catch (RequestFailedException storageRequestFailedException)
when (storageRequestFailedException.ErrorCode == BlobErrorCode.BlobAlreadyExists)
{
return default;
}
catch (Exception ex)
{
ClientConfiguration.Pipeline.LogException(ex);
throw;
}
finally
{
ClientConfiguration.Pipeline.LogMethodExit(nameof(PageBlobClient));
}
}
}