| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Buffers; |
| | 6 | | using System.ComponentModel; |
| | 7 | | using System.IO; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using Azure.Core; |
| | 11 | | using Azure.Core.Pipeline; |
| | 12 | | using Azure.Storage.Blobs.Models; |
| | 13 | | using Azure.Storage.Blobs.Specialized; |
| | 14 | | using Azure.Storage.Cryptography; |
| | 15 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 16 | | using Tags = System.Collections.Generic.IDictionary<string, string>; |
| | 17 | |
|
| | 18 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 19 | |
|
| | 20 | | namespace Azure.Storage.Blobs |
| | 21 | | { |
| | 22 | | /// <summary> |
| | 23 | | /// The <see cref="BlobClient"/> allows you to manipulate Azure Storage |
| | 24 | | /// blobs. |
| | 25 | | /// </summary> |
| | 26 | | public class BlobClient : BlobBaseClient |
| | 27 | | { |
| | 28 | | #region ctors |
| | 29 | | /// <summary> |
| | 30 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 31 | | /// class for mocking. |
| | 32 | | /// </summary> |
| 2200 | 33 | | protected BlobClient() |
| | 34 | | { |
| 2200 | 35 | | } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 39 | | /// class. |
| | 40 | | /// </summary> |
| | 41 | | /// <param name="connectionString"> |
| | 42 | | /// A connection string includes the authentication information |
| | 43 | | /// required for your application to access data in an Azure Storage |
| | 44 | | /// account at runtime. |
| | 45 | | /// |
| | 46 | | /// For more information, |
| | 47 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 48 | | /// Configure Azure Storage connection strings</see>. |
| | 49 | | /// </param> |
| | 50 | | /// <param name="blobContainerName"> |
| | 51 | | /// The name of the container containing this blob. |
| | 52 | | /// </param> |
| | 53 | | /// <param name="blobName"> |
| | 54 | | /// The name of this blob. |
| | 55 | | /// </param> |
| | 56 | | public BlobClient(string connectionString, string blobContainerName, string blobName) |
| 4 | 57 | | : base(connectionString, blobContainerName, blobName) |
| | 58 | | { |
| 4 | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 63 | | /// class. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name="connectionString"> |
| | 66 | | /// A connection string includes the authentication information |
| | 67 | | /// required for your application to access data in an Azure Storage |
| | 68 | | /// account at runtime. |
| | 69 | | /// |
| | 70 | | /// For more information, |
| | 71 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 72 | | /// Configure Azure Storage connection strings</see>. |
| | 73 | | /// </param> |
| | 74 | | /// <param name="blobContainerName"> |
| | 75 | | /// The name of the container containing this blob. |
| | 76 | | /// </param> |
| | 77 | | /// <param name="blobName"> |
| | 78 | | /// The name of this blob. |
| | 79 | | /// </param> |
| | 80 | | /// <param name="options"> |
| | 81 | | /// Optional client options that define the transport pipeline |
| | 82 | | /// policies for authentication, retries, etc., that are applied to |
| | 83 | | /// every request. |
| | 84 | | /// </param> |
| | 85 | | public BlobClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options) |
| 36 | 86 | | : base(connectionString, blobContainerName, blobName, options) |
| | 87 | | { |
| 36 | 88 | | } |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 92 | | /// class. |
| | 93 | | /// </summary> |
| | 94 | | /// <param name="blobUri"> |
| | 95 | | /// A <see cref="Uri"/> referencing the blob that includes the |
| | 96 | | /// name of the account, the name of the container, and the name of |
| | 97 | | /// the blob. |
| | 98 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}". |
| | 99 | | /// </param> |
| | 100 | | /// <param name="options"> |
| | 101 | | /// Optional client options that define the transport pipeline |
| | 102 | | /// policies for authentication, retries, etc., that are applied to |
| | 103 | | /// every request. |
| | 104 | | /// </param> |
| | 105 | | public BlobClient(Uri blobUri, BlobClientOptions options = default) |
| 28 | 106 | | : base(blobUri, options) |
| | 107 | | { |
| 24 | 108 | | } |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 112 | | /// class. |
| | 113 | | /// </summary> |
| | 114 | | /// <param name="blobUri"> |
| | 115 | | /// A <see cref="Uri"/> referencing the blob that includes the |
| | 116 | | /// name of the account, the name of the container, and the name of |
| | 117 | | /// the blob. |
| | 118 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}". |
| | 119 | | /// </param> |
| | 120 | | /// <param name="credential"> |
| | 121 | | /// The shared key credential used to sign requests. |
| | 122 | | /// </param> |
| | 123 | | /// <param name="options"> |
| | 124 | | /// Optional client options that define the transport pipeline |
| | 125 | | /// policies for authentication, retries, etc., that are applied to |
| | 126 | | /// every request. |
| | 127 | | /// </param> |
| | 128 | | public BlobClient(Uri blobUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) |
| 100 | 129 | | : base(blobUri, credential, options) |
| | 130 | | { |
| 100 | 131 | | } |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 135 | | /// class. |
| | 136 | | /// </summary> |
| | 137 | | /// <param name="blobUri"> |
| | 138 | | /// A <see cref="Uri"/> referencing the blob that includes the |
| | 139 | | /// name of the account, the name of the container, and the name of |
| | 140 | | /// the blob. |
| | 141 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}". |
| | 142 | | /// </param> |
| | 143 | | /// <param name="credential"> |
| | 144 | | /// The token credential used to sign requests. |
| | 145 | | /// </param> |
| | 146 | | /// <param name="options"> |
| | 147 | | /// Optional client options that define the transport pipeline |
| | 148 | | /// policies for authentication, retries, etc., that are applied to |
| | 149 | | /// every request. |
| | 150 | | /// </param> |
| | 151 | | public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions options = default) |
| 8 | 152 | | : base(blobUri, credential, options) |
| | 153 | | { |
| 4 | 154 | | } |
| | 155 | |
|
| | 156 | | /// <summary> |
| | 157 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 158 | | /// class. |
| | 159 | | /// </summary> |
| | 160 | | /// <param name="blobUri"> |
| | 161 | | /// A <see cref="Uri"/> referencing the blob that includes the |
| | 162 | | /// name of the account, the name of the container, and the name of |
| | 163 | | /// the blob. |
| | 164 | | /// This is likely to be similar to "https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}". |
| | 165 | | /// </param> |
| | 166 | | /// <param name="pipeline"> |
| | 167 | | /// The transport pipeline used to send every request. |
| | 168 | | /// </param> |
| | 169 | | /// <param name="version"> |
| | 170 | | /// The version of the service to use when sending requests. |
| | 171 | | /// </param> |
| | 172 | | /// <param name="clientDiagnostics">Client diagnostics.</param> |
| | 173 | | /// <param name="customerProvidedKey">Customer provided key.</param> |
| | 174 | | /// <param name="clientSideEncryption">Client-side encryption options.</param> |
| | 175 | | /// <param name="encryptionScope">Encryption scope.</param> |
| | 176 | | internal BlobClient( |
| | 177 | | Uri blobUri, |
| | 178 | | HttpPipeline pipeline, |
| | 179 | | BlobClientOptions.ServiceVersion version, |
| | 180 | | ClientDiagnostics clientDiagnostics, |
| | 181 | | CustomerProvidedKey? customerProvidedKey, |
| | 182 | | ClientSideEncryptionOptions clientSideEncryption, |
| | 183 | | string encryptionScope) |
| 2084 | 184 | | : base(blobUri, pipeline, version, clientDiagnostics, customerProvidedKey, clientSideEncryption, encryptionS |
| | 185 | | { |
| 2084 | 186 | | } |
| | 187 | | #endregion ctors |
| | 188 | |
|
| | 189 | | /// <summary> |
| | 190 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 191 | | /// class with an identical <see cref="Uri"/> source but the specified |
| | 192 | | /// <paramref name="snapshot"/> timestamp. |
| | 193 | | /// |
| | 194 | | /// For more information, see <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/creating-a-sn |
| | 195 | | /// </summary> |
| | 196 | | /// <param name="snapshot">The snapshot identifier.</param> |
| | 197 | | /// <returns>A new <see cref="BlobClient"/> instance.</returns> |
| | 198 | | /// <remarks> |
| | 199 | | /// Pass null or empty string to remove the snapshot returning a URL |
| | 200 | | /// to the base blob. |
| | 201 | | /// </remarks> |
| | 202 | | public new BlobClient WithSnapshot(string snapshot) |
| | 203 | | { |
| 8 | 204 | | BlobUriBuilder blobUriBuilder = new BlobUriBuilder(Uri) |
| 8 | 205 | | { |
| 8 | 206 | | Snapshot = snapshot |
| 8 | 207 | | }; |
| | 208 | |
|
| 8 | 209 | | return new BlobClient( |
| 8 | 210 | | blobUriBuilder.ToUri(), |
| 8 | 211 | | Pipeline, |
| 8 | 212 | | Version, |
| 8 | 213 | | ClientDiagnostics, |
| 8 | 214 | | CustomerProvidedKey, |
| 8 | 215 | | ClientSideEncryption, |
| 8 | 216 | | EncryptionScope); |
| | 217 | | } |
| | 218 | |
|
| | 219 | | /// <summary> |
| | 220 | | /// Initializes a new instance of the <see cref="BlobClient"/> |
| | 221 | | /// class with an identical <see cref="Uri"/> source but the specified |
| | 222 | | /// <paramref name="versionId"/> timestamp. |
| | 223 | | /// |
| | 224 | | /// </summary> |
| | 225 | | /// <param name="versionId">The version identifier.</param> |
| | 226 | | /// <returns>A new <see cref="BlobClient"/> instance.</returns> |
| | 227 | | /// <remarks> |
| | 228 | | /// Pass null or empty string to remove the version returning a URL |
| | 229 | | /// to the base blob. |
| | 230 | | /// </remarks> |
| | 231 | | public new BlobClient WithVersion(string versionId) |
| | 232 | | { |
| 4 | 233 | | BlobUriBuilder blobUriBuilder = new BlobUriBuilder(Uri) |
| 4 | 234 | | { |
| 4 | 235 | | VersionId = versionId |
| 4 | 236 | | }; |
| | 237 | |
|
| 4 | 238 | | return new BlobClient( |
| 4 | 239 | | blobUriBuilder.ToUri(), |
| 4 | 240 | | Pipeline, |
| 4 | 241 | | Version, |
| 4 | 242 | | ClientDiagnostics, |
| 4 | 243 | | CustomerProvidedKey, |
| 4 | 244 | | ClientSideEncryption, |
| 4 | 245 | | EncryptionScope); |
| | 246 | | } |
| | 247 | |
|
| | 248 | | #region Upload |
| | 249 | | /// <summary> |
| | 250 | | /// The <see cref="Upload(Stream)"/> operation creates a new block blob |
| | 251 | | /// or updates the content of an existing block blob. Updating an |
| | 252 | | /// existing block blob overwrites any existing metadata on the blob. |
| | 253 | | /// |
| | 254 | | /// For partial block blob updates and other advanced features, please |
| | 255 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 256 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 257 | | /// <see cref="AppendBlobClient"/>. |
| | 258 | | /// |
| | 259 | | /// For more information, see |
| | 260 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 261 | | /// Put Blob</see>. |
| | 262 | | /// </summary> |
| | 263 | | /// <param name="content"> |
| | 264 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 265 | | /// </param> |
| | 266 | | /// <returns> |
| | 267 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 268 | | /// state of the updated block blob. |
| | 269 | | /// </returns> |
| | 270 | | /// <remarks> |
| | 271 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 272 | | /// a failure occurs. |
| | 273 | | /// </remarks> |
| | 274 | | public virtual Response<BlobContentInfo> Upload(Stream content) => |
| 646 | 275 | | Upload(content, CancellationToken.None); |
| | 276 | |
|
| | 277 | | /// <summary> |
| | 278 | | /// The <see cref="Upload(string)"/> operation creates a new block blob |
| | 279 | | /// or updates the content of an existing block blob. Updating an |
| | 280 | | /// existing block blob overwrites any existing metadata on the blob. |
| | 281 | | /// |
| | 282 | | /// For partial block blob updates and other advanced features, please |
| | 283 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 284 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 285 | | /// <see cref="AppendBlobClient"/>. |
| | 286 | | /// |
| | 287 | | /// For more information, see |
| | 288 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 289 | | /// Put Blob</see>. |
| | 290 | | /// </summary> |
| | 291 | | /// <param name="path"> |
| | 292 | | /// A file path containing the content to upload. |
| | 293 | | /// </param> |
| | 294 | | /// <returns> |
| | 295 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 296 | | /// state of the updated block blob. |
| | 297 | | /// </returns> |
| | 298 | | /// <remarks> |
| | 299 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 300 | | /// a failure occurs. |
| | 301 | | /// </remarks> |
| | 302 | | public virtual Response<BlobContentInfo> Upload(string path) => |
| 14 | 303 | | Upload(path, CancellationToken.None); |
| | 304 | |
|
| | 305 | | /// <summary> |
| | 306 | | /// The <see cref="UploadAsync(Stream)"/> operation creates a new block blob |
| | 307 | | /// or updates the content of an existing block blob. Updating an |
| | 308 | | /// existing block blob overwrites any existing metadata on the blob. |
| | 309 | | /// |
| | 310 | | /// For partial block blob updates and other advanced features, please |
| | 311 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 312 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 313 | | /// <see cref="AppendBlobClient"/>. |
| | 314 | | /// |
| | 315 | | /// For more information, see |
| | 316 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 317 | | /// Put Blob</see>. |
| | 318 | | /// </summary> |
| | 319 | | /// <param name="content"> |
| | 320 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 321 | | /// </param> |
| | 322 | | /// <returns> |
| | 323 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 324 | | /// state of the updated block blob. |
| | 325 | | /// </returns> |
| | 326 | | /// <remarks> |
| | 327 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 328 | | /// a failure occurs. |
| | 329 | | /// </remarks> |
| | 330 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync(Stream content) => |
| 662 | 331 | | await UploadAsync(content, CancellationToken.None).ConfigureAwait(false); |
| | 332 | |
|
| | 333 | | /// <summary> |
| | 334 | | /// The <see cref="UploadAsync(string)"/> operation creates a new block blob |
| | 335 | | /// or updates the content of an existing block blob. Updating an |
| | 336 | | /// existing block blob overwrites any existing metadata on the blob. |
| | 337 | | /// |
| | 338 | | /// For partial block blob updates and other advanced features, please |
| | 339 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 340 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 341 | | /// <see cref="AppendBlobClient"/>. |
| | 342 | | /// |
| | 343 | | /// For more information, see |
| | 344 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 345 | | /// Put Blob</see>. |
| | 346 | | /// </summary> |
| | 347 | | /// <param name="path"> |
| | 348 | | /// A file path containing the content to upload. |
| | 349 | | /// </param> |
| | 350 | | /// <returns> |
| | 351 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 352 | | /// state of the updated block blob. |
| | 353 | | /// </returns> |
| | 354 | | /// <remarks> |
| | 355 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 356 | | /// a failure occurs. |
| | 357 | | /// </remarks> |
| | 358 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync(string path) => |
| 14 | 359 | | await UploadAsync(path, CancellationToken.None).ConfigureAwait(false); |
| | 360 | |
|
| | 361 | | /// <summary> |
| | 362 | | /// The <see cref="Upload(Stream, CancellationToken)"/> operation |
| | 363 | | /// creates a new block blob or updates the content of an existing |
| | 364 | | /// block blob. Updating an existing block blob overwrites any |
| | 365 | | /// existing metadata on the blob. |
| | 366 | | /// |
| | 367 | | /// For partial block blob updates and other advanced features, please |
| | 368 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 369 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 370 | | /// <see cref="AppendBlobClient"/>. |
| | 371 | | /// |
| | 372 | | /// For more information, see |
| | 373 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 374 | | /// Put Blob</see>. |
| | 375 | | /// </summary> |
| | 376 | | /// <param name="content"> |
| | 377 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 378 | | /// </param> |
| | 379 | | /// <param name="cancellationToken"> |
| | 380 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 381 | | /// notifications that the operation should be cancelled. |
| | 382 | | /// </param> |
| | 383 | | /// <returns> |
| | 384 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 385 | | /// state of the updated block blob. |
| | 386 | | /// </returns> |
| | 387 | | /// <remarks> |
| | 388 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 389 | | /// a failure occurs. |
| | 390 | | /// </remarks> |
| | 391 | | public virtual Response<BlobContentInfo> Upload( |
| | 392 | | Stream content, |
| | 393 | | CancellationToken cancellationToken) => |
| 648 | 394 | | Upload( |
| 648 | 395 | | content, |
| 648 | 396 | | overwrite: false, |
| 648 | 397 | | cancellationToken: cancellationToken); |
| | 398 | |
|
| | 399 | | /// <summary> |
| | 400 | | /// The <see cref="Upload(string, CancellationToken)"/> operation |
| | 401 | | /// creates a new block blob or updates the content of an existing |
| | 402 | | /// block blob. Updating an existing block blob overwrites any |
| | 403 | | /// existing metadata on the blob. |
| | 404 | | /// |
| | 405 | | /// For partial block blob updates and other advanced features, please |
| | 406 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 407 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 408 | | /// <see cref="AppendBlobClient"/>. |
| | 409 | | /// |
| | 410 | | /// For more information, see |
| | 411 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 412 | | /// Put Blob</see>. |
| | 413 | | /// </summary> |
| | 414 | | /// <param name="path"> |
| | 415 | | /// A file path containing the content to upload. |
| | 416 | | /// </param> |
| | 417 | | /// <param name="cancellationToken"> |
| | 418 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 419 | | /// notifications that the operation should be cancelled. |
| | 420 | | /// </param> |
| | 421 | | /// <returns> |
| | 422 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 423 | | /// state of the updated block blob. |
| | 424 | | /// </returns> |
| | 425 | | /// <remarks> |
| | 426 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 427 | | /// a failure occurs. |
| | 428 | | /// </remarks> |
| | 429 | | public virtual Response<BlobContentInfo> Upload( |
| | 430 | | string path, |
| | 431 | | CancellationToken cancellationToken) => |
| 14 | 432 | | Upload( |
| 14 | 433 | | path, |
| 14 | 434 | | overwrite: false, |
| 14 | 435 | | cancellationToken: cancellationToken); |
| | 436 | |
|
| | 437 | | /// <summary> |
| | 438 | | /// The <see cref="UploadAsync(Stream, CancellationToken)"/> operation |
| | 439 | | /// creates a new block blob or updates the content of an existing |
| | 440 | | /// block blob. Updating an existing block blob overwrites any |
| | 441 | | /// existing metadata on the blob. |
| | 442 | | /// |
| | 443 | | /// For partial block blob updates and other advanced features, please |
| | 444 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 445 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 446 | | /// <see cref="AppendBlobClient"/>. |
| | 447 | | /// |
| | 448 | | /// For more information, see |
| | 449 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 450 | | /// Put Blob</see>. |
| | 451 | | /// </summary> |
| | 452 | | /// <param name="content"> |
| | 453 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 454 | | /// </param> |
| | 455 | | /// <param name="cancellationToken"> |
| | 456 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 457 | | /// notifications that the operation should be cancelled. |
| | 458 | | /// </param> |
| | 459 | | /// <returns> |
| | 460 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 461 | | /// state of the updated block blob. |
| | 462 | | /// </returns> |
| | 463 | | /// <remarks> |
| | 464 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 465 | | /// a failure occurs. |
| | 466 | | /// </remarks> |
| | 467 | | public virtual Task<Response<BlobContentInfo>> UploadAsync( |
| | 468 | | Stream content, |
| | 469 | | CancellationToken cancellationToken) => |
| 664 | 470 | | UploadAsync( |
| 664 | 471 | | content, |
| 664 | 472 | | overwrite: false, |
| 664 | 473 | | cancellationToken: cancellationToken); |
| | 474 | |
|
| | 475 | | /// <summary> |
| | 476 | | /// The <see cref="UploadAsync(string, CancellationToken)"/> operation |
| | 477 | | /// creates a new block blob or updates the content of an existing |
| | 478 | | /// block blob. Updating an existing block blob overwrites any |
| | 479 | | /// existing metadata on the blob. |
| | 480 | | /// |
| | 481 | | /// For partial block blob updates and other advanced features, please |
| | 482 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 483 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 484 | | /// <see cref="AppendBlobClient"/>. |
| | 485 | | /// |
| | 486 | | /// For more information, see |
| | 487 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 488 | | /// Put Blob</see>. |
| | 489 | | /// </summary> |
| | 490 | | /// <param name="path"> |
| | 491 | | /// A file path containing the content to upload. |
| | 492 | | /// </param> |
| | 493 | | /// <param name="cancellationToken"> |
| | 494 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 495 | | /// notifications that the operation should be cancelled. |
| | 496 | | /// </param> |
| | 497 | | /// <returns> |
| | 498 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 499 | | /// state of the updated block blob. |
| | 500 | | /// </returns> |
| | 501 | | /// <remarks> |
| | 502 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 503 | | /// a failure occurs. |
| | 504 | | /// </remarks> |
| | 505 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync( |
| | 506 | | string path, |
| | 507 | | CancellationToken cancellationToken) => |
| 14 | 508 | | await UploadAsync( |
| 14 | 509 | | path, |
| 14 | 510 | | overwrite: false, |
| 14 | 511 | | cancellationToken: cancellationToken) |
| 14 | 512 | | .ConfigureAwait(false); |
| | 513 | |
|
| | 514 | | /// <summary> |
| | 515 | | /// The <see cref="Upload(Stream, CancellationToken)"/> operation |
| | 516 | | /// creates a new block blob or updates the content of an existing |
| | 517 | | /// block blob. Updating an existing block blob overwrites any |
| | 518 | | /// existing metadata on the blob. |
| | 519 | | /// |
| | 520 | | /// For partial block blob updates and other advanced features, please |
| | 521 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 522 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 523 | | /// <see cref="AppendBlobClient"/>. |
| | 524 | | /// |
| | 525 | | /// For more information, see |
| | 526 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 527 | | /// Put Blob</see>. |
| | 528 | | /// </summary> |
| | 529 | | /// <param name="content"> |
| | 530 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 531 | | /// </param> |
| | 532 | | /// <param name="overwrite"> |
| | 533 | | /// Whether the upload should overwrite any existing blobs. The |
| | 534 | | /// default value is false. |
| | 535 | | /// </param> |
| | 536 | | /// <param name="cancellationToken"> |
| | 537 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 538 | | /// notifications that the operation should be cancelled. |
| | 539 | | /// </param> |
| | 540 | | /// <returns> |
| | 541 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 542 | | /// state of the updated block blob. |
| | 543 | | /// </returns> |
| | 544 | | /// <remarks> |
| | 545 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 546 | | /// a failure occurs. |
| | 547 | | /// </remarks> |
| | 548 | | public virtual Response<BlobContentInfo> Upload( |
| | 549 | | Stream content, |
| | 550 | | bool overwrite = false, |
| | 551 | | CancellationToken cancellationToken = default) => |
| 666 | 552 | | Upload( |
| 666 | 553 | | content, |
| 666 | 554 | | conditions: overwrite ? null : new BlobRequestConditions { IfNoneMatch = new ETag(Constants.Wildcard) }, |
| 666 | 555 | | cancellationToken: cancellationToken); |
| | 556 | |
|
| | 557 | | /// <summary> |
| | 558 | | /// The <see cref="Upload(string, CancellationToken)"/> operation |
| | 559 | | /// creates a new block blob or updates the content of an existing |
| | 560 | | /// block blob. Updating an existing block blob overwrites any |
| | 561 | | /// existing metadata on the blob. |
| | 562 | | /// |
| | 563 | | /// For partial block blob updates and other advanced features, please |
| | 564 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 565 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 566 | | /// <see cref="AppendBlobClient"/>. |
| | 567 | | /// |
| | 568 | | /// For more information, see |
| | 569 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 570 | | /// Put Blob</see>. |
| | 571 | | /// </summary> |
| | 572 | | /// <param name="path"> |
| | 573 | | /// A file path containing the content to upload. |
| | 574 | | /// </param> |
| | 575 | | /// <param name="overwrite"> |
| | 576 | | /// Whether the upload should overwrite any existing blobs. The |
| | 577 | | /// default value is false. |
| | 578 | | /// </param> |
| | 579 | | /// <param name="cancellationToken"> |
| | 580 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 581 | | /// notifications that the operation should be cancelled. |
| | 582 | | /// </param> |
| | 583 | | /// <returns> |
| | 584 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 585 | | /// state of the updated block blob. |
| | 586 | | /// </returns> |
| | 587 | | /// <remarks> |
| | 588 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 589 | | /// a failure occurs. |
| | 590 | | /// </remarks> |
| | 591 | | public virtual Response<BlobContentInfo> Upload( |
| | 592 | | string path, |
| | 593 | | bool overwrite = false, |
| | 594 | | CancellationToken cancellationToken = default) => |
| 20 | 595 | | Upload( |
| 20 | 596 | | path, |
| 20 | 597 | | conditions: overwrite ? null : new BlobRequestConditions { IfNoneMatch = new ETag(Constants.Wildcard) }, |
| 20 | 598 | | cancellationToken: cancellationToken); |
| | 599 | |
|
| | 600 | | /// <summary> |
| | 601 | | /// The <see cref="UploadAsync(Stream, CancellationToken)"/> operation |
| | 602 | | /// creates a new block blob or updates the content of an existing |
| | 603 | | /// block blob. Updating an existing block blob overwrites any |
| | 604 | | /// existing metadata on the blob. |
| | 605 | | /// |
| | 606 | | /// For partial block blob updates and other advanced features, please |
| | 607 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 608 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 609 | | /// <see cref="AppendBlobClient"/>. |
| | 610 | | /// |
| | 611 | | /// For more information, see |
| | 612 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 613 | | /// Put Blob</see>. |
| | 614 | | /// </summary> |
| | 615 | | /// <param name="content"> |
| | 616 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 617 | | /// </param> |
| | 618 | | /// <param name="overwrite"> |
| | 619 | | /// Whether the upload should overwrite any existing blobs. The |
| | 620 | | /// default value is false. |
| | 621 | | /// </param> |
| | 622 | | /// <param name="cancellationToken"> |
| | 623 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 624 | | /// notifications that the operation should be cancelled. |
| | 625 | | /// </param> |
| | 626 | | /// <returns> |
| | 627 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 628 | | /// state of the updated block blob. |
| | 629 | | /// </returns> |
| | 630 | | /// <remarks> |
| | 631 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 632 | | /// a failure occurs. |
| | 633 | | /// </remarks> |
| | 634 | | public virtual Task<Response<BlobContentInfo>> UploadAsync( |
| | 635 | | Stream content, |
| | 636 | | bool overwrite = false, |
| | 637 | | CancellationToken cancellationToken = default) => |
| 682 | 638 | | UploadAsync( |
| 682 | 639 | | content, |
| 682 | 640 | | conditions: overwrite ? null : new BlobRequestConditions { IfNoneMatch = new ETag(Constants.Wildcard) }, |
| 682 | 641 | | cancellationToken: cancellationToken); |
| | 642 | |
|
| | 643 | | /// <summary> |
| | 644 | | /// The <see cref="UploadAsync(string, CancellationToken)"/> operation |
| | 645 | | /// creates a new block blob or updates the content of an existing |
| | 646 | | /// block blob. Updating an existing block blob overwrites any |
| | 647 | | /// existing metadata on the blob. |
| | 648 | | /// |
| | 649 | | /// For partial block blob updates and other advanced features, please |
| | 650 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 651 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 652 | | /// <see cref="AppendBlobClient"/>. |
| | 653 | | /// |
| | 654 | | /// For more information, see |
| | 655 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 656 | | /// Put Blob</see>. |
| | 657 | | /// </summary> |
| | 658 | | /// <param name="path"> |
| | 659 | | /// A file path containing the content to upload. |
| | 660 | | /// </param> |
| | 661 | | /// <param name="overwrite"> |
| | 662 | | /// Whether the upload should overwrite any existing blobs. The |
| | 663 | | /// default value is false. |
| | 664 | | /// </param> |
| | 665 | | /// <param name="cancellationToken"> |
| | 666 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 667 | | /// notifications that the operation should be cancelled. |
| | 668 | | /// </param> |
| | 669 | | /// <returns> |
| | 670 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 671 | | /// state of the updated block blob. |
| | 672 | | /// </returns> |
| | 673 | | /// <remarks> |
| | 674 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 675 | | /// a failure occurs. |
| | 676 | | /// </remarks> |
| | 677 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync( |
| | 678 | | string path, |
| | 679 | | bool overwrite = false, |
| | 680 | | CancellationToken cancellationToken = default) => |
| 20 | 681 | | await UploadAsync( |
| 20 | 682 | | path, |
| 20 | 683 | | conditions: overwrite ? null : new BlobRequestConditions { IfNoneMatch = new ETag(Constants.Wildcard) }, |
| 20 | 684 | | cancellationToken: cancellationToken) |
| 20 | 685 | | .ConfigureAwait(false); |
| | 686 | |
|
| | 687 | | /// <summary> |
| | 688 | | /// The <see cref="Upload(Stream, BlobUploadOptions, CancellationToken)"/> |
| | 689 | | /// operation creates a new block blob or updates the content of an |
| | 690 | | /// existing block blob. Updating an existing block blob overwrites |
| | 691 | | /// any existing metadata on the blob. |
| | 692 | | /// |
| | 693 | | /// For partial block blob updates and other advanced features, please |
| | 694 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 695 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 696 | | /// <see cref="AppendBlobClient"/>. |
| | 697 | | /// |
| | 698 | | /// For more information, see |
| | 699 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 700 | | /// Put Blob</see>. |
| | 701 | | /// </summary> |
| | 702 | | /// <param name="content"> |
| | 703 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 704 | | /// </param> |
| | 705 | | /// <param name="options"> |
| | 706 | | /// Optional parameters. |
| | 707 | | /// </param> |
| | 708 | | /// <param name="cancellationToken"> |
| | 709 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 710 | | /// notifications that the operation should be cancelled. |
| | 711 | | /// </param> |
| | 712 | | /// <returns> |
| | 713 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 714 | | /// state of the updated block blob. |
| | 715 | | /// </returns> |
| | 716 | | /// <remarks> |
| | 717 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 718 | | /// a failure occurs. |
| | 719 | | /// </remarks> |
| | 720 | | public virtual Response<BlobContentInfo> Upload( |
| | 721 | | Stream content, |
| | 722 | | BlobUploadOptions options, |
| | 723 | | CancellationToken cancellationToken = default) => |
| 2 | 724 | | StagedUploadInternal( |
| 2 | 725 | | content, |
| 2 | 726 | | options, |
| 2 | 727 | | async: false, |
| 2 | 728 | | cancellationToken: cancellationToken) |
| 2 | 729 | | .EnsureCompleted(); |
| | 730 | |
|
| | 731 | | /// <summary> |
| | 732 | | /// The <see cref="Upload(Stream, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, AccessTier? |
| | 733 | | /// operation creates a new block blob or updates the content of an |
| | 734 | | /// existing block blob. Updating an existing block blob overwrites |
| | 735 | | /// any existing metadata on the blob. |
| | 736 | | /// |
| | 737 | | /// For partial block blob updates and other advanced features, please |
| | 738 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 739 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 740 | | /// <see cref="AppendBlobClient"/>. |
| | 741 | | /// |
| | 742 | | /// For more information, |
| | 743 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 744 | | /// Put Blob</see>. |
| | 745 | | /// </summary> |
| | 746 | | /// <param name="content"> |
| | 747 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 748 | | /// </param> |
| | 749 | | /// <param name="httpHeaders"> |
| | 750 | | /// Optional standard HTTP header properties that can be set for the |
| | 751 | | /// block blob. |
| | 752 | | /// </param> |
| | 753 | | /// <param name="metadata"> |
| | 754 | | /// Optional custom metadata to set for this block blob. |
| | 755 | | /// </param> |
| | 756 | | /// <param name="conditions"> |
| | 757 | | /// Optional <see cref="BlobRequestConditions"/> to add conditions on |
| | 758 | | /// the creation of this new block blob. |
| | 759 | | /// </param> |
| | 760 | | /// <param name="progressHandler"> |
| | 761 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 762 | | /// progress updates about data transfers. |
| | 763 | | /// </param> |
| | 764 | | /// <param name="accessTier"> |
| | 765 | | /// Optional <see cref="AccessTier"/> |
| | 766 | | /// Indicates the tier to be set on the blob. |
| | 767 | | /// </param> |
| | 768 | | /// <param name="transferOptions"> |
| | 769 | | /// Optional <see cref="StorageTransferOptions"/> to configure |
| | 770 | | /// parallel transfer behavior. |
| | 771 | | /// </param> |
| | 772 | | /// <param name="cancellationToken"> |
| | 773 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 774 | | /// notifications that the operation should be cancelled. |
| | 775 | | /// </param> |
| | 776 | | /// <returns> |
| | 777 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 778 | | /// state of the updated block blob. |
| | 779 | | /// </returns> |
| | 780 | | /// <remarks> |
| | 781 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 782 | | /// a failure occurs. |
| | 783 | | /// </remarks> |
| | 784 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 785 | | public virtual Response<BlobContentInfo> Upload( |
| | 786 | | Stream content, |
| | 787 | | BlobHttpHeaders httpHeaders = default, |
| | 788 | | Metadata metadata = default, |
| | 789 | | BlobRequestConditions conditions = default, |
| | 790 | | IProgress<long> progressHandler = default, |
| | 791 | | AccessTier? accessTier = default, |
| | 792 | | StorageTransferOptions transferOptions = default, |
| | 793 | | CancellationToken cancellationToken = default) => |
| 678 | 794 | | StagedUploadInternal( |
| 678 | 795 | | content, |
| 678 | 796 | | new BlobUploadOptions |
| 678 | 797 | | { |
| 678 | 798 | | HttpHeaders = httpHeaders, |
| 678 | 799 | | Metadata = metadata, |
| 678 | 800 | | Conditions = conditions, |
| 678 | 801 | | ProgressHandler = progressHandler, |
| 678 | 802 | | AccessTier = accessTier, |
| 678 | 803 | | TransferOptions = transferOptions |
| 678 | 804 | | }, |
| 678 | 805 | | async: false, |
| 678 | 806 | | cancellationToken: cancellationToken) |
| 678 | 807 | | .EnsureCompleted(); |
| | 808 | |
|
| | 809 | | /// <summary> |
| | 810 | | /// The <see cref="Upload(string, BlobUploadOptions, CancellationToken)"/> |
| | 811 | | /// operation creates a new block blob or updates the content of an |
| | 812 | | /// existing block blob. Updating an existing block blob overwrites |
| | 813 | | /// any existing metadata on the blob. |
| | 814 | | /// |
| | 815 | | /// For partial block blob updates and other advanced features, please |
| | 816 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 817 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 818 | | /// <see cref="AppendBlobClient"/>. |
| | 819 | | /// |
| | 820 | | /// For more information, see |
| | 821 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 822 | | /// Put Blob</see>. |
| | 823 | | /// </summary> |
| | 824 | | /// <param name="path"> |
| | 825 | | /// A file path containing the content to upload. |
| | 826 | | /// </param> |
| | 827 | | /// <param name="options"> |
| | 828 | | /// Optional parameters. |
| | 829 | | /// </param> |
| | 830 | | /// <param name="cancellationToken"> |
| | 831 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 832 | | /// notifications that the operation should be cancelled. |
| | 833 | | /// </param> |
| | 834 | | /// <returns> |
| | 835 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 836 | | /// state of the updated block blob. |
| | 837 | | /// </returns> |
| | 838 | | /// <remarks> |
| | 839 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 840 | | /// a failure occurs. |
| | 841 | | /// </remarks> |
| | 842 | | public virtual Response<BlobContentInfo> Upload( |
| | 843 | | string path, |
| | 844 | | BlobUploadOptions options, |
| | 845 | | CancellationToken cancellationToken = default) |
| | 846 | | { |
| 2 | 847 | | using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 848 | | { |
| 2 | 849 | | return StagedUploadInternal( |
| 2 | 850 | | stream, |
| 2 | 851 | | options, |
| 2 | 852 | | async: false, |
| 2 | 853 | | cancellationToken: cancellationToken) |
| 2 | 854 | | .EnsureCompleted(); |
| | 855 | | } |
| 2 | 856 | | } |
| | 857 | |
|
| | 858 | | /// <summary> |
| | 859 | | /// The <see cref="Upload(string, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, AccessTier? |
| | 860 | | /// operation creates a new block blob or updates the content of an |
| | 861 | | /// existing block blob. Updating an existing block blob overwrites |
| | 862 | | /// any existing metadata on the blob. |
| | 863 | | /// |
| | 864 | | /// For partial block blob updates and other advanced features, please |
| | 865 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 866 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 867 | | /// <see cref="AppendBlobClient"/>. |
| | 868 | | /// |
| | 869 | | /// For more information, see |
| | 870 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 871 | | /// Put Blob</see>. |
| | 872 | | /// </summary> |
| | 873 | | /// <param name="path"> |
| | 874 | | /// A file path containing the content to upload. |
| | 875 | | /// </param> |
| | 876 | | /// <param name="httpHeaders"> |
| | 877 | | /// Optional standard HTTP header properties that can be set for the |
| | 878 | | /// block blob. |
| | 879 | | /// </param> |
| | 880 | | /// <param name="metadata"> |
| | 881 | | /// Optional custom metadata to set for this block blob. |
| | 882 | | /// </param> |
| | 883 | | /// <param name="conditions"> |
| | 884 | | /// Optional <see cref="BlobRequestConditions"/> to add conditions on |
| | 885 | | /// the creation of this new block blob. |
| | 886 | | /// </param> |
| | 887 | | /// <param name="progressHandler"> |
| | 888 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 889 | | /// progress updates about data transfers. |
| | 890 | | /// </param> |
| | 891 | | /// <param name="accessTier"> |
| | 892 | | /// Optional <see cref="AccessTier"/> |
| | 893 | | /// Indicates the tier to be set on the blob. |
| | 894 | | /// </param> |
| | 895 | | /// <param name="transferOptions"> |
| | 896 | | /// Optional <see cref="StorageTransferOptions"/> to configure |
| | 897 | | /// parallel transfer behavior. |
| | 898 | | /// </param> |
| | 899 | | /// <param name="cancellationToken"> |
| | 900 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 901 | | /// notifications that the operation should be cancelled. |
| | 902 | | /// </param> |
| | 903 | | /// <returns> |
| | 904 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 905 | | /// state of the updated block blob. |
| | 906 | | /// </returns> |
| | 907 | | /// <remarks> |
| | 908 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 909 | | /// a failure occurs. |
| | 910 | | /// </remarks> |
| | 911 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 912 | | public virtual Response<BlobContentInfo> Upload( |
| | 913 | | string path, |
| | 914 | | BlobHttpHeaders httpHeaders = default, |
| | 915 | | Metadata metadata = default, |
| | 916 | | BlobRequestConditions conditions = default, |
| | 917 | | IProgress<long> progressHandler = default, |
| | 918 | | AccessTier? accessTier = default, |
| | 919 | | StorageTransferOptions transferOptions = default, |
| | 920 | | CancellationToken cancellationToken = default) |
| | 921 | | { |
| 36 | 922 | | using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 923 | | { |
| 36 | 924 | | return StagedUploadInternal( |
| 36 | 925 | | stream, |
| 36 | 926 | | new BlobUploadOptions |
| 36 | 927 | | { |
| 36 | 928 | | HttpHeaders = httpHeaders, |
| 36 | 929 | | Metadata = metadata, |
| 36 | 930 | | Conditions = conditions, |
| 36 | 931 | | ProgressHandler = progressHandler, |
| 36 | 932 | | AccessTier = accessTier, |
| 36 | 933 | | TransferOptions = transferOptions |
| 36 | 934 | | }, |
| 36 | 935 | | async: false, |
| 36 | 936 | | cancellationToken: cancellationToken) |
| 36 | 937 | | .EnsureCompleted(); |
| | 938 | | } |
| 30 | 939 | | } |
| | 940 | |
|
| | 941 | | /// <summary> |
| | 942 | | /// The <see cref="UploadAsync(Stream, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, Access |
| | 943 | | /// operation creates a new block blob or updates the content of an |
| | 944 | | /// existing block blob. Updating an existing block blob overwrites |
| | 945 | | /// any existing metadata on the blob. |
| | 946 | | /// |
| | 947 | | /// For partial block blob updates and other advanced features, please |
| | 948 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 949 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 950 | | /// <see cref="AppendBlobClient"/>. |
| | 951 | | /// |
| | 952 | | /// For more information, see |
| | 953 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 954 | | /// Put Blob</see>. |
| | 955 | | /// </summary> |
| | 956 | | /// <param name="content"> |
| | 957 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 958 | | /// </param> |
| | 959 | | /// <param name="options"> |
| | 960 | | /// Optional parameters. |
| | 961 | | /// </param> |
| | 962 | | /// <param name="cancellationToken"> |
| | 963 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 964 | | /// notifications that the operation should be cancelled. |
| | 965 | | /// </param> |
| | 966 | | /// <returns> |
| | 967 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 968 | | /// state of the updated block blob. |
| | 969 | | /// </returns> |
| | 970 | | /// <remarks> |
| | 971 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 972 | | /// a failure occurs. |
| | 973 | | /// </remarks> |
| | 974 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync( |
| | 975 | | Stream content, |
| | 976 | | BlobUploadOptions options, |
| | 977 | | CancellationToken cancellationToken = default) => |
| 2 | 978 | | await StagedUploadInternal( |
| 2 | 979 | | content, |
| 2 | 980 | | options, |
| 2 | 981 | | async: true, |
| 2 | 982 | | cancellationToken: cancellationToken) |
| 2 | 983 | | .ConfigureAwait(false); |
| | 984 | |
|
| | 985 | | /// <summary> |
| | 986 | | /// The <see cref="UploadAsync(Stream, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, Access |
| | 987 | | /// operation creates a new block blob or updates the content of an |
| | 988 | | /// existing block blob. Updating an existing block blob overwrites |
| | 989 | | /// any existing metadata on the blob. |
| | 990 | | /// |
| | 991 | | /// For partial block blob updates and other advanced features, please |
| | 992 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 993 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 994 | | /// <see cref="AppendBlobClient"/>. |
| | 995 | | /// |
| | 996 | | /// For more information, see |
| | 997 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 998 | | /// Put Blob</see>. |
| | 999 | | /// </summary> |
| | 1000 | | /// <param name="content"> |
| | 1001 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 1002 | | /// </param> |
| | 1003 | | /// <param name="httpHeaders"> |
| | 1004 | | /// Optional standard HTTP header properties that can be set for the |
| | 1005 | | /// block blob. |
| | 1006 | | /// </param> |
| | 1007 | | /// <param name="metadata"> |
| | 1008 | | /// Optional custom metadata to set for this block blob. |
| | 1009 | | /// </param> |
| | 1010 | | /// <param name="conditions"> |
| | 1011 | | /// Optional <see cref="BlobRequestConditions"/> to add conditions on |
| | 1012 | | /// the creation of this new block blob. |
| | 1013 | | /// </param> |
| | 1014 | | /// <param name="transferOptions"> |
| | 1015 | | /// Optional <see cref="StorageTransferOptions"/> to configure |
| | 1016 | | /// parallel transfer behavior. |
| | 1017 | | /// </param> |
| | 1018 | | /// <param name="progressHandler"> |
| | 1019 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 1020 | | /// progress updates about data transfers. |
| | 1021 | | /// </param> |
| | 1022 | | /// <param name="accessTier"> |
| | 1023 | | /// Optional <see cref="AccessTier"/> |
| | 1024 | | /// Indicates the tier to be set on the blob. |
| | 1025 | | /// </param> |
| | 1026 | | /// <param name="cancellationToken"> |
| | 1027 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1028 | | /// notifications that the operation should be cancelled. |
| | 1029 | | /// </param> |
| | 1030 | | /// <returns> |
| | 1031 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 1032 | | /// state of the updated block blob. |
| | 1033 | | /// </returns> |
| | 1034 | | /// <remarks> |
| | 1035 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1036 | | /// a failure occurs. |
| | 1037 | | /// </remarks> |
| | 1038 | | [ForwardsClientCalls] |
| | 1039 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1040 | | public virtual Task<Response<BlobContentInfo>> UploadAsync( |
| | 1041 | | Stream content, |
| | 1042 | | BlobHttpHeaders httpHeaders = default, |
| | 1043 | | Metadata metadata = default, |
| | 1044 | | BlobRequestConditions conditions = default, |
| | 1045 | | IProgress<long> progressHandler = default, |
| | 1046 | | AccessTier? accessTier = default, |
| | 1047 | | StorageTransferOptions transferOptions = default, |
| | 1048 | | CancellationToken cancellationToken = default) => |
| 694 | 1049 | | StagedUploadInternal( |
| 694 | 1050 | | content, |
| 694 | 1051 | | new BlobUploadOptions |
| 694 | 1052 | | { |
| 694 | 1053 | | HttpHeaders = httpHeaders, |
| 694 | 1054 | | Metadata = metadata, |
| 694 | 1055 | | Conditions = conditions, |
| 694 | 1056 | | ProgressHandler = progressHandler, |
| 694 | 1057 | | AccessTier = accessTier, |
| 694 | 1058 | | TransferOptions = transferOptions |
| 694 | 1059 | | }, |
| 694 | 1060 | | async: true, |
| 694 | 1061 | | cancellationToken: cancellationToken); |
| | 1062 | |
|
| | 1063 | | /// <summary> |
| | 1064 | | /// The <see cref="UploadAsync(Stream, BlobUploadOptions, CancellationToken)"/> |
| | 1065 | | /// operation creates a new block blob or updates the content of an |
| | 1066 | | /// existing block blob. Updating an existing block blob overwrites |
| | 1067 | | /// any existing metadata on the blob. |
| | 1068 | | /// |
| | 1069 | | /// For partial block blob updates and other advanced features, please |
| | 1070 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 1071 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 1072 | | /// <see cref="AppendBlobClient"/>. |
| | 1073 | | /// |
| | 1074 | | /// For more information, see |
| | 1075 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 1076 | | /// Put Blob</see>.. |
| | 1077 | | /// </summary> |
| | 1078 | | /// <param name="path"> |
| | 1079 | | /// A file path containing the content to upload. |
| | 1080 | | /// </param> |
| | 1081 | | /// <param name="options"> |
| | 1082 | | /// Optional parameters. |
| | 1083 | | /// </param> |
| | 1084 | | /// <param name="cancellationToken"> |
| | 1085 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1086 | | /// notifications that the operation should be cancelled. |
| | 1087 | | /// </param> |
| | 1088 | | /// <returns> |
| | 1089 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 1090 | | /// state of the updated block blob. |
| | 1091 | | /// </returns> |
| | 1092 | | /// <remarks> |
| | 1093 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1094 | | /// a failure occurs. |
| | 1095 | | /// </remarks> |
| | 1096 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync( |
| | 1097 | | string path, |
| | 1098 | | BlobUploadOptions options, |
| | 1099 | | CancellationToken cancellationToken = default) |
| | 1100 | | { |
| 2 | 1101 | | using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 1102 | | { |
| 2 | 1103 | | return await StagedUploadInternal( |
| 2 | 1104 | | stream, |
| 2 | 1105 | | options, |
| 2 | 1106 | | async: true, |
| 2 | 1107 | | cancellationToken: cancellationToken) |
| 2 | 1108 | | .ConfigureAwait(false); |
| | 1109 | | } |
| 2 | 1110 | | } |
| | 1111 | |
|
| | 1112 | | /// <summary> |
| | 1113 | | /// The <see cref="UploadAsync(string, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, Access |
| | 1114 | | /// operation creates a new block blob or updates the content of an |
| | 1115 | | /// existing block blob. Updating an existing block blob overwrites |
| | 1116 | | /// any existing metadata on the blob. |
| | 1117 | | /// |
| | 1118 | | /// For partial block blob updates and other advanced features, please |
| | 1119 | | /// see <see cref="BlockBlobClient"/>. To create or modify page or |
| | 1120 | | /// append blobs, please see <see cref="PageBlobClient"/> or |
| | 1121 | | /// <see cref="AppendBlobClient"/>. |
| | 1122 | | /// |
| | 1123 | | /// For more information, see |
| | 1124 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-blob"> |
| | 1125 | | /// Put Blob</see>. |
| | 1126 | | /// </summary> |
| | 1127 | | /// <param name="path"> |
| | 1128 | | /// A file path containing the content to upload. |
| | 1129 | | /// </param> |
| | 1130 | | /// <param name="httpHeaders"> |
| | 1131 | | /// Optional standard HTTP header properties that can be set for the |
| | 1132 | | /// block blob. |
| | 1133 | | /// </param> |
| | 1134 | | /// <param name="metadata"> |
| | 1135 | | /// Optional custom metadata to set for this block blob. |
| | 1136 | | /// </param> |
| | 1137 | | /// <param name="conditions"> |
| | 1138 | | /// Optional <see cref="BlobRequestConditions"/> to add conditions on |
| | 1139 | | /// the creation of this new block blob. |
| | 1140 | | /// </param> |
| | 1141 | | /// <param name="progressHandler"> |
| | 1142 | | /// Optional <see cref="IProgress{Long}"/> to provide |
| | 1143 | | /// progress updates about data transfers. |
| | 1144 | | /// </param> |
| | 1145 | | /// <param name="accessTier"> |
| | 1146 | | /// Optional <see cref="AccessTier"/> |
| | 1147 | | /// Indicates the tier to be set on the blob. |
| | 1148 | | /// </param> |
| | 1149 | | /// <param name="transferOptions"> |
| | 1150 | | /// Optional <see cref="StorageTransferOptions"/> to configure |
| | 1151 | | /// parallel transfer behavior. |
| | 1152 | | /// </param> |
| | 1153 | | /// <param name="cancellationToken"> |
| | 1154 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1155 | | /// notifications that the operation should be cancelled. |
| | 1156 | | /// </param> |
| | 1157 | | /// <returns> |
| | 1158 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 1159 | | /// state of the updated block blob. |
| | 1160 | | /// </returns> |
| | 1161 | | /// <remarks> |
| | 1162 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1163 | | /// a failure occurs. |
| | 1164 | | /// </remarks> |
| | 1165 | | [ForwardsClientCalls] |
| | 1166 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1167 | | public virtual async Task<Response<BlobContentInfo>> UploadAsync( |
| | 1168 | | string path, |
| | 1169 | | BlobHttpHeaders httpHeaders = default, |
| | 1170 | | Metadata metadata = default, |
| | 1171 | | BlobRequestConditions conditions = default, |
| | 1172 | | IProgress<long> progressHandler = default, |
| | 1173 | | AccessTier? accessTier = default, |
| | 1174 | | StorageTransferOptions transferOptions = default, |
| | 1175 | | CancellationToken cancellationToken = default) |
| | 1176 | | { |
| 36 | 1177 | | using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 1178 | | { |
| 36 | 1179 | | return await StagedUploadInternal( |
| 36 | 1180 | | stream, |
| 36 | 1181 | | new BlobUploadOptions |
| 36 | 1182 | | { |
| 36 | 1183 | | HttpHeaders = httpHeaders, |
| 36 | 1184 | | Metadata = metadata, |
| 36 | 1185 | | Conditions = conditions, |
| 36 | 1186 | | ProgressHandler = progressHandler, |
| 36 | 1187 | | AccessTier = accessTier, |
| 36 | 1188 | | TransferOptions = transferOptions |
| 36 | 1189 | | }, |
| 36 | 1190 | | async: true, |
| 36 | 1191 | | cancellationToken).ConfigureAwait(false); |
| | 1192 | | } |
| 30 | 1193 | | } |
| | 1194 | |
|
| | 1195 | | /// <summary> |
| | 1196 | | /// This operation will create a new |
| | 1197 | | /// block blob of arbitrary size by uploading it as indiviually staged |
| | 1198 | | /// blocks if it's larger than the |
| | 1199 | | /// <paramref name="options"/> MaximumTransferLength. |
| | 1200 | | /// </summary> |
| | 1201 | | /// <param name="content"> |
| | 1202 | | /// A <see cref="Stream"/> containing the content to upload. |
| | 1203 | | /// </param> |
| | 1204 | | /// <param name="options"> |
| | 1205 | | /// Options for this upload. |
| | 1206 | | /// </param> |
| | 1207 | | /// <param name="async"> |
| | 1208 | | /// </param> |
| | 1209 | | /// <param name="cancellationToken"> |
| | 1210 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1211 | | /// notifications that the operation should be cancelled. |
| | 1212 | | /// </param> |
| | 1213 | | /// <returns> |
| | 1214 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 1215 | | /// state of the updated block blob. |
| | 1216 | | /// </returns> |
| | 1217 | | /// <remarks> |
| | 1218 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1219 | | /// a failure occurs. |
| | 1220 | | /// </remarks> |
| | 1221 | | internal async Task<Response<BlobContentInfo>> StagedUploadInternal( |
| | 1222 | | Stream content, |
| | 1223 | | BlobUploadOptions options, |
| | 1224 | | bool async = true, |
| | 1225 | | CancellationToken cancellationToken = default) |
| | 1226 | | { |
| 1516 | 1227 | | if (UsingClientSideEncryption) |
| | 1228 | | { |
| | 1229 | | // content is now unseekable, so PartitionedUploader will be forced to do a buffered multipart upload |
| 0 | 1230 | | (content, options.Metadata) = await new BlobClientSideEncryptor(new ClientSideEncryptor(ClientSideEncryp |
| 0 | 1231 | | .ClientSideEncryptInternal(content, options.Metadata, async, cancellationToken).ConfigureAwait(false |
| | 1232 | | } |
| | 1233 | |
|
| 1516 | 1234 | | var client = new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionS |
| | 1235 | |
|
| 1516 | 1236 | | var uploader = GetPartitionedUploader( |
| 1516 | 1237 | | transferOptions: options?.TransferOptions ?? default, |
| 1516 | 1238 | | operationName: $"{nameof(BlobClient)}.{nameof(Upload)}"); |
| | 1239 | |
|
| 1516 | 1240 | | return await uploader.UploadInternal( |
| 1516 | 1241 | | content, |
| 1516 | 1242 | | options, |
| 1516 | 1243 | | options.ProgressHandler, |
| 1516 | 1244 | | async, |
| 1516 | 1245 | | cancellationToken) |
| 1516 | 1246 | | .ConfigureAwait(false); |
| 1488 | 1247 | | } |
| | 1248 | |
|
| | 1249 | | /// <summary> |
| | 1250 | | /// This operation will create a new |
| | 1251 | | /// block blob of arbitrary size by uploading it as indiviually staged |
| | 1252 | | /// blocks if it's larger than the |
| | 1253 | | /// <paramref name="options"/>. MaximumTransferLength. |
| | 1254 | | /// </summary> |
| | 1255 | | /// <param name="path"> |
| | 1256 | | /// A file path of the file to upload. |
| | 1257 | | /// </param> |
| | 1258 | | /// <param name="options"> |
| | 1259 | | /// Options for this upload. |
| | 1260 | | /// </param> |
| | 1261 | | /// <param name="async"> |
| | 1262 | | /// </param> |
| | 1263 | | /// <param name="cancellationToken"> |
| | 1264 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1265 | | /// notifications that the operation should be cancelled. |
| | 1266 | | /// </param> |
| | 1267 | | /// <returns> |
| | 1268 | | /// A <see cref="Response{BlobContentInfo}"/> describing the |
| | 1269 | | /// state of the updated block blob. |
| | 1270 | | /// </returns> |
| | 1271 | | /// <remarks> |
| | 1272 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1273 | | /// a failure occurs. |
| | 1274 | | /// </remarks> |
| | 1275 | | internal async Task<Response<BlobContentInfo>> StagedUploadInternal( |
| | 1276 | | string path, |
| | 1277 | | BlobUploadOptions options, |
| | 1278 | | bool async = true, |
| | 1279 | | CancellationToken cancellationToken = default) |
| | 1280 | | { |
| | 1281 | | // TODO Upload from file will get it's own implementation in the future that opens more |
| | 1282 | | // than one stream at once. This is incompatible with .NET's CryptoStream. We will |
| | 1283 | | // need to uncomment the below code and revert to upload from stream if client-side |
| | 1284 | | // encryption is enabled. |
| | 1285 | | //if (ClientSideEncryption != default) |
| | 1286 | | //{ |
| | 1287 | | // using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 1288 | | // { |
| | 1289 | | // return await StagedUploadAsync( |
| | 1290 | | // stream, |
| | 1291 | | // blobHttpHeaders, |
| | 1292 | | // metadata, |
| | 1293 | | // conditions, |
| | 1294 | | // progressHandler, |
| | 1295 | | // accessTier, |
| | 1296 | | // transferOptions: transferOptions, |
| | 1297 | | // async: async, |
| | 1298 | | // cancellationToken: cancellationToken) |
| | 1299 | | // .ConfigureAwait(false); |
| | 1300 | | // } |
| | 1301 | | //} |
| | 1302 | |
|
| 32 | 1303 | | using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | 1304 | | { |
| 32 | 1305 | | return await StagedUploadInternal( |
| 32 | 1306 | | stream, |
| 32 | 1307 | | options, |
| 32 | 1308 | | async: async, |
| 32 | 1309 | | cancellationToken: cancellationToken) |
| 32 | 1310 | | .ConfigureAwait(false); |
| | 1311 | | } |
| 32 | 1312 | | } |
| | 1313 | | #endregion Upload |
| | 1314 | |
|
| | 1315 | | internal PartitionedUploader<BlobUploadOptions, BlobContentInfo> GetPartitionedUploader( |
| | 1316 | | StorageTransferOptions transferOptions, |
| | 1317 | | ArrayPool<byte> arrayPool = null, |
| | 1318 | | string operationName = null) |
| 1516 | 1319 | | => new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope) |
| 1516 | 1320 | | .GetPartitionedUploader(transferOptions, arrayPool, operationName); |
| | 1321 | | } |
| | 1322 | | } |