in sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs [1437:1863]
public virtual Response<BlockInfo> StageBlockFromUri(
Uri sourceUri,
string base64BlockId,
StageBlockFromUriOptions options = default,
CancellationToken cancellationToken = default) =>
StageBlockFromUriInternal(
sourceUri,
base64BlockId,
options?.SourceRange ?? default,
options?.SourceContentHash,
options?.SourceConditions,
options?.DestinationConditions,
options?.SourceAuthentication,
options?.SourceShareTokenIntent,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="StageBlockFromUriAsync(Uri, string, StageBlockFromUriOptions, CancellationToken)"/>
/// operation creates a new block to be committed as part of a blob where the contents are
/// read from the <paramref name="sourceUri" />.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/put-block-from-url">
/// Put Block From URL</see>.
/// </summary>
/// <param name="sourceUri">
/// Specifies the <see cref="Uri"/> of the source blob. The value may
/// be a URL of up to 2 KB in length that specifies a blob. The
/// source blob must either be public or must be authenticated via a
/// shared access signature. If the source blob is public, no
/// authentication is required to perform the operation.
/// </param>
/// <param name="base64BlockId">
/// A valid Base64 string value that identifies the block. Prior to
/// encoding, the string must be less than or equal to 64 bytes in
/// size. For a given blob, the length of the value specified for
/// the <paramref name="base64BlockId"/> parameter must be the same
/// size for each block. Note that the Base64 string will be
/// URL-encoded.
/// </param>
/// <param name="options">
/// Optional parameters. <see cref="StageBlockFromUriOptions"/>.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlockInfo}"/> describing the
/// state of the updated block.
/// </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<BlockInfo>> StageBlockFromUriAsync(
Uri sourceUri,
string base64BlockId,
StageBlockFromUriOptions options = default,
CancellationToken cancellationToken = default) =>
await StageBlockFromUriInternal(
sourceUri,
base64BlockId,
options?.SourceRange ?? default,
options?.SourceContentHash,
options?.SourceConditions,
options?.DestinationConditions,
options?.SourceAuthentication,
options?.SourceShareTokenIntent,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="StageBlockFromUri(Uri, string, HttpRange, byte[], RequestConditions, BlobRequestConditions, CancellationToken)"/>
/// operation creates a new block to be committed as part of a blob where the contents are
/// read from the <paramref name="sourceUri" />.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/put-block-from-url">
/// Put Block From URL</see>.
/// </summary>
/// <param name="sourceUri">
/// Specifies the <see cref="Uri"/> of the source blob. The value may
/// be a URL of up to 2 KB in length that specifies a blob. The
/// source blob must either be public or must be authenticated via a
/// shared access signature. If the source blob is public, no
/// authentication is required to perform the operation.
/// </param>
/// <param name="base64BlockId">
/// A valid Base64 string value that identifies the block. Prior to
/// encoding, the string must be less than or equal to 64 bytes in
/// size. For a given blob, the length of the value specified for
/// the <paramref name="base64BlockId"/> parameter must be the same
/// size for each block. Note that the Base64 string will be
/// URL-encoded.
/// </param>
/// <param name="sourceRange">
/// Optionally uploads only the bytes of the blob in the
/// <paramref name="sourceUri"/> in the specified range. If this is
/// not specified, the entire source blob contents are uploaded as a
/// single block.
/// </param>
/// <param name="sourceContentHash">
/// Optional MD5 hash of the block content from the
/// <paramref name="sourceUri"/>. This hash is used to verify the
/// integrity of the block during transport of the data from the Uri.
/// When this hash is specified, the storage service compares the hash
/// of the content that has arrived from the <paramref name="sourceUri"/>
/// with this value. Note that this md5 hash is not stored with the
/// blob. If the two hashes do not match, the operation will fail
/// with a <see cref="RequestFailedException"/>.
/// </param>
/// <param name="sourceConditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on the copying of data from this source blob.
/// </param>
/// <param name="conditions">
/// Optional <see cref="BlobRequestConditions"/> to add
/// conditions on the staging of this block.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlockInfo}"/> describing the
/// state of the updated block 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)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
public virtual Response<BlockInfo> StageBlockFromUri(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
Uri sourceUri,
string base64BlockId,
HttpRange sourceRange,
byte[] sourceContentHash,
RequestConditions sourceConditions,
BlobRequestConditions conditions,
CancellationToken cancellationToken) =>
StageBlockFromUriInternal(
sourceUri,
base64BlockId,
sourceRange,
sourceContentHash,
sourceConditions,
conditions,
sourceAuthentication: default,
sourceShareTokenIntent: default,
async: false,
cancellationToken)
.EnsureCompleted();
/// <summary>
/// The <see cref="StageBlockFromUriAsync(Uri, string, HttpRange, byte[], RequestConditions, BlobRequestConditions, CancellationToken)"/>
/// operation creates a new block to be committed as part of a blob where the contents are
/// read from the <paramref name="sourceUri" />.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/put-block-from-url">
/// Put Block From URL</see>.
/// </summary>
/// <param name="sourceUri">
/// Specifies the <see cref="Uri"/> of the source blob. The value may
/// be a URL of up to 2 KB in length that specifies a blob. The
/// source blob must either be public or must be authenticated via a
/// shared access signature. If the source blob is public, no
/// authentication is required to perform the operation.
/// </param>
/// <param name="base64BlockId">
/// A valid Base64 string value that identifies the block. Prior to
/// encoding, the string must be less than or equal to 64 bytes in
/// size. For a given blob, the length of the value specified for
/// the <paramref name="base64BlockId"/> parameter must be the same
/// size for each block. Note that the Base64 string will be
/// URL-encoded.
/// </param>
/// <param name="sourceRange">
/// Optionally uploads only the bytes of the blob in the
/// <paramref name="sourceUri"/> in the specified range. If this is
/// not specified, the entire source blob contents are uploaded as a
/// single block.
/// </param>
/// <param name="sourceContentHash">
/// Optional MD5 hash of the block content from the
/// <paramref name="sourceUri"/>. This hash is used to verify the
/// integrity of the block during transport of the data from the Uri.
/// When this hash is specified, the storage service compares the hash
/// of the content that has arrived from the <paramref name="sourceUri"/>
/// with this value. Note that this md5 hash is not stored with the
/// blob. If the two hashes do not match, the operation will fail
/// with a <see cref="RequestFailedException"/>.
/// </param>
/// <param name="sourceConditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on the copying of data from this source blob.
/// </param>
/// <param name="conditions">
/// Optional <see cref="BlobRequestConditions"/> to add
/// conditions on the staging of this block.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{BlockInfo}"/> describing the
/// state of the updated block.
/// </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)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
public virtual async Task<Response<BlockInfo>> StageBlockFromUriAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
Uri sourceUri,
string base64BlockId,
HttpRange sourceRange,
byte[] sourceContentHash,
RequestConditions sourceConditions,
BlobRequestConditions conditions,
CancellationToken cancellationToken) =>
await StageBlockFromUriInternal(
sourceUri,
base64BlockId,
sourceRange,
sourceContentHash,
sourceConditions,
conditions,
sourceAuthentication: default,
sourceShareTokenIntent: default,
async: true,
cancellationToken)
.ConfigureAwait(false);
/// <summary>
/// The <see cref="StageBlockFromUriInternal"/> operation creates a new
/// block to be committed as part of a blob where the contents are
/// read from the <paramref name="sourceUri" />.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/put-block-from-url">
/// Put Block From URL</see>.
/// </summary>
/// <param name="sourceUri">
/// Specifies the <see cref="Uri"/> of the source blob. The value may
/// be a URL of up to 2 KB in length that specifies a blob. The
/// source blob must either be public or must be authenticated via a
/// shared access signature. If the source blob is public, no
/// authentication is required to perform the operation.
/// </param>
/// <param name="base64BlockId">
/// A valid Base64 string value that identifies the block. Prior to
/// encoding, the string must be less than or equal to 64 bytes in
/// size. For a given blob, the length of the value specified for
/// the <paramref name="base64BlockId"/> parameter must be the same
/// size for each block. Note that the Base64 string will be
/// URL-encoded.
/// </param>
/// <param name="sourceRange">
/// Optionally uploads only the bytes of the blob in the
/// <paramref name="sourceUri"/> in the specified range. If this is
/// not specified, the entire source blob contents are uploaded as a
/// single block.
/// </param>
/// <param name="sourceContentHash">
/// Optional MD5 hash of the block content from the
/// <paramref name="sourceUri"/>. This hash is used to verify the
/// integrity of the block during transport of the data from the Uri.
/// When this hash is specified, the storage service compares the hash
/// of the content that has arrived from the <paramref name="sourceUri"/>
/// with this value. Note that this md5 hash is not stored with the
/// blob. If the two hashes do not match, the operation will fail
/// with a <see cref="RequestFailedException"/>.
/// </param>
/// <param name="sourceConditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on the copying of data from this source blob.
/// </param>
/// <param name="conditions">
/// Optional <see cref="BlobRequestConditions"/> to add
/// conditions on the staging of this block.
/// </param>
/// <param name="sourceAuthentication">
/// Optional. Source bearer token used to access the source blob.
/// </param>
/// <param name="sourceShareTokenIntent">
/// Optional, only applicable (but required) when the source is Azure Storage Files and using token authentication.
/// Used to indicate the intent of the request.
/// </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>
/// A <see cref="Response{BlockInfo}"/> describing the
/// state of the updated block.
/// </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<BlockInfo>> StageBlockFromUriInternal(
Uri sourceUri,
string base64BlockId,
HttpRange sourceRange,
byte[] sourceContentHash,
RequestConditions sourceConditions,
BlobRequestConditions conditions,
HttpAuthorization sourceAuthentication,
FileShareTokenIntent? sourceShareTokenIntent,
bool async,
CancellationToken cancellationToken)
{
using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(BlockBlobClient)))
{
ClientConfiguration.Pipeline.LogMethodEnter(
nameof(BlockBlobClient),
message:
$"{nameof(Uri)}: {Uri}\n" +
$"{nameof(base64BlockId)}: {base64BlockId}\n" +
$"{nameof(sourceUri)}: {sourceUri}\n" +
$"{nameof(conditions)}: {conditions}");
DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlockBlobClient)}.{nameof(StageBlockFromUri)}");
conditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.IfModifiedSince
| BlobRequestConditionProperty.IfUnmodifiedSince
| BlobRequestConditionProperty.TagConditions
| BlobRequestConditionProperty.IfMatch
| BlobRequestConditionProperty.IfNoneMatch,
operationName: nameof(BlockBlobClient.StageBlockFromUri),
parameterName: nameof(conditions));
// All RequestConditions are valid for sourceConditions.
sourceConditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlockBlobClient.StageBlockFromUri),
parameterName: nameof(sourceConditions));
try
{
scope.Start();
ResponseWithHeaders<BlockBlobStageBlockFromURLHeaders> response;
if (async)
{
response = await BlockBlobRestClient.StageBlockFromURLAsync(
blockId: base64BlockId,
contentLength: 0,
sourceUrl: sourceUri.AbsoluteUri,
sourceRange: sourceRange.ToString(),
sourceContentMD5: sourceContentHash,
encryptionKey: ClientConfiguration.CustomerProvidedKey?.EncryptionKey,
encryptionKeySha256: ClientConfiguration.CustomerProvidedKey?.EncryptionKeyHash,
encryptionAlgorithm: ClientConfiguration.CustomerProvidedKey?.EncryptionAlgorithm == null ? null : EncryptionAlgorithmTypeInternal.AES256,
encryptionScope: ClientConfiguration.EncryptionScope,
leaseId: conditions?.LeaseId,
sourceIfModifiedSince: sourceConditions?.IfModifiedSince,
sourceIfUnmodifiedSince: sourceConditions?.IfUnmodifiedSince,
sourceIfMatch: sourceConditions?.IfMatch?.ToString(),
sourceIfNoneMatch: sourceConditions?.IfNoneMatch?.ToString(),
copySourceAuthorization: sourceAuthentication?.ToString(),
fileRequestIntent: sourceShareTokenIntent,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
else
{
response = BlockBlobRestClient.StageBlockFromURL(
blockId: base64BlockId,
contentLength: 0,
sourceUrl: sourceUri.AbsoluteUri,
sourceRange: sourceRange.ToString(),
sourceContentMD5: sourceContentHash,
encryptionKey: ClientConfiguration.CustomerProvidedKey?.EncryptionKey,
encryptionKeySha256: ClientConfiguration.CustomerProvidedKey?.EncryptionKeyHash,
encryptionAlgorithm: ClientConfiguration.CustomerProvidedKey?.EncryptionAlgorithm == null ? null : EncryptionAlgorithmTypeInternal.AES256,
encryptionScope: ClientConfiguration.EncryptionScope,
leaseId: conditions?.LeaseId,
sourceIfModifiedSince: sourceConditions?.IfModifiedSince,
sourceIfUnmodifiedSince: sourceConditions?.IfUnmodifiedSince,
sourceIfMatch: sourceConditions?.IfMatch?.ToString(),
sourceIfNoneMatch: sourceConditions?.IfNoneMatch?.ToString(),
copySourceAuthorization: sourceAuthentication?.ToString(),
fileRequestIntent: sourceShareTokenIntent,
cancellationToken: cancellationToken);
}
return Response.FromValue(
response.ToBlockInfo(),
response.GetRawResponse());
}
catch (Exception ex)
{
ClientConfiguration.Pipeline.LogException(ex);
scope.Failed(ex);
throw;
}
finally
{
ClientConfiguration.Pipeline.LogMethodExit(nameof(BlockBlobClient));
scope.Dispose();
}
}
}