public async Task UploadFileToBlobAsync(string sourceFilePath, BlobOptions options)
        {
            Validate.BlobContainerName(options.ContainerName, "containerName");
            Validate.BlobName(options.BlobName, "blobName");

            var destinationBlob = DataManagerUtility.GetCloudBlob(options);
            TransferManager.Configurations.ParallelOperations = 64;

            var context = new TransferContext
            {
                OverwriteCallback = (path, destinationPath) => options.OverwriteDestination
            };

            ProgressRecorder = new ProgressRecorder();
            context.ProgressHandler = ProgressRecorder;

            await TransferManager.UploadAsync(sourceFilePath, destinationBlob, null, context, CancellationToken.None);
        }
        public async Task UploadFileToBlobAsync(string sourceFilePath, BlobOptions options)
        {
            Validate.BlobContainerName(options.ContainerName, "containerName");
            Validate.BlobName(options.BlobName, "blobName");

            var destinationBlob = DataManagerUtility.GetCloudBlob(options);

            TransferManager.Configurations.ParallelOperations = 64;

            var context = new TransferContext
            {
                OverwriteCallback = (path, destinationPath) => options.OverwriteDestination
            };

            ProgressRecorder        = new ProgressRecorder();
            context.ProgressHandler = ProgressRecorder;

            await TransferManager.UploadAsync(sourceFilePath, destinationBlob, null, context, CancellationToken.None);
        }
示例#3
0
        /// <summary>
        /// Get a CloudBlob instance with the specified name and type in the given container.
        /// </summary>
        /// <param name="options">BlobOptions</param>
        /// <returns>A CloudBlob instance with the specified name and type in the given container.</returns>
        public static CloudBlob GetCloudBlob(BlobOptions options)
        {
            var client    = GetCloudBlobClient(options.ConnectionString);
            var container = client.GetContainerReference(options.ContainerName);

            container.CreateIfNotExists();

            CloudBlob cloudBlob;

            switch (options.BlobType)
            {
            case BlobType.AppendBlob:
                cloudBlob = container.GetAppendBlobReference(options.BlobName);
                break;

            case BlobType.BlockBlob:
                cloudBlob = container.GetBlockBlobReference(options.BlobName);
                break;

            case BlobType.PageBlob:
                cloudBlob = container.GetPageBlobReference(options.BlobName);
                break;

            default:
                throw new ArgumentException($"Invalid blob type {options.BlobName}");
            }

            if (options.Public)
            {
                var permission = container.GetPermissions();

                permission.PublicAccess = BlobContainerPublicAccessType.Container;
                container.SetPermissions(permission);
            }

            return(cloudBlob);
        }