private static async Task BlobUploadTest()
        {
            string sourceFilename = "Downloads.zip";
            string destinationFilename = "Downloads_blockblob.zip";

            CloudBlob destinationBlob = GetCloudBlob(ContainerName, destinationFilename, BlobType.BlockBlob);
            UploadOptions options = new UploadOptions();
            options.ContentType = "application/zip";

            try
            {
                await TransferManager.UploadAsync(sourceFilename, destinationBlob, options, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("File {0} is uploaded to {1} successfully.", sourceFilename, destinationBlob.Uri.ToString());
        }
        public void TestSetContentType()
        {
            string contentType = "contenttype";
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                UploadOptions uploadOptions = new UploadOptions();
                uploadOptions.ContentType = "contenttype";

                transferItem.Options = uploadOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");

            FileNode destFileNode = result.DataInfo.RootNode.GetFileNode(DMLibTestBase.FileName);
            Test.Assert(contentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, contentType);
        }
 public virtual Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Upload a file to Azure Blob Storage.
 /// </summary>
 /// <param name="sourcePath">Path to the source file.</param>
 /// <param name="destBlob">The <see cref="CloudBlob"/> that is the destination Azure blob.</param>
 /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
 /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
 /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
 public static Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
 {
     TransferLocation sourceLocation = new TransferLocation(sourcePath);
     TransferLocation destLocation = new TransferLocation(destBlob);
     return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken);
 }
 /// <summary>
 /// Upload a file to Azure Blob Storage.
 /// </summary>
 /// <param name="sourcePath">Path to the source file.</param>
 /// <param name="destBlob">The <see cref="CloudBlob"/> that is the destination Azure blob.</param>
 /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
 /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
 /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
 public static Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context)
 {
     return UploadAsync(sourcePath, destBlob, options, context, CancellationToken.None);
 }
        private static Task UploadInternalAsync(TransferLocation sourceLocation, TransferLocation destLocation, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            if (options != null)
            {
                destLocation.AccessCondition = options.DestinationAccessCondition;
            }

            Transfer transfer = CreateSingleObjectTransfer(sourceLocation, destLocation, TransferMethod.SyncCopy, context);
            if (options != null)
            {
                transfer.ContentType = options.ContentType;
            }

            return DoTransfer(transfer, cancellationToken);
        }
 /// <summary>
 /// Upload a file to Azure File Storage.
 /// </summary>
 /// <param name="sourceStream">A <see cref="System.IO.Stream"/> object providing the file content.</param>
 /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param>
 /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
 /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
 /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
 public static Task UploadAsync(Stream sourceStream, CloudFile destFile, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
 {
     TransferLocation sourceLocation = new TransferLocation(sourceStream);
     TransferLocation destLocation = new TransferLocation(destFile);
     return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken);
 }
 /// <summary>
 /// Upload a file to Azure File Storage.
 /// </summary>
 /// <param name="sourceStream">A <see cref="System.IO.Stream"/> object providing the file content.</param>
 /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param>
 /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
 /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
 /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
 public static Task UploadAsync(Stream sourceStream, CloudFile destFile, UploadOptions options, TransferContext context)
 {
     return UploadAsync(sourceStream, destFile, options, context, CancellationToken.None);
 }
 /// <summary>
 /// Upload a file to Azure Blob Storage.
 /// </summary>
 /// <param name="sourcePath">Path to the source file.</param>
 /// <param name="destBlob">The Microsoft.WindowsAzure.Storage.Blob.CloudBlob that is the destination Azure blob.</param>
 /// <param name="options">An Microsoft.WindowsAzure.Storage.DataMovement.UploadOptions object that specifies
 ///     additional options for the operation.</param>
 /// <param name="context">A Microsoft.WindowsAzure.Storage.DataMovement.TransferContext object that represents
 ///     the context for the current operation.</param>
 /// <param name="cancellationToken">A System.Threading.CancellationToken object to observe while waiting for a task
 ///     to complete.</param>
 /// <returns>A System.Threading.Tasks.Task object that represents the asynchronous operation.</returns>
 public Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
 {
     return TransferManager.UploadAsync(sourcePath, destBlob, options, context, cancellationToken);
 }
        /// <summary>
        /// Upload a file to Azure File Storage.
        /// </summary>
        /// <param name="sourceStream">A <see cref="System.IO.Stream"/> object providing the file content.</param>
        /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param>
        /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        public static Task UploadAsync(Stream sourceStream, CloudFile destFile, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            StreamLocation sourceLocation = new StreamLocation(sourceStream);
            AzureFileLocation destLocation = new AzureFileLocation(destFile);
            if (options != null)
            {
                destLocation.AccessCondition = options.DestinationAccessCondition;
            }

            return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken);
        }
        /// <summary>
        /// Upload a file to Azure Blob Storage.
        /// </summary>
        /// <param name="sourcePath">Path to the source file.</param>
        /// <param name="destBlob">The <see cref="CloudBlob"/> that is the destination Azure blob.</param>
        /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        public static Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            FileLocation sourceLocation = new FileLocation(sourcePath);
            AzureBlobLocation destLocation = new AzureBlobLocation(destBlob);
            if (options != null)
            {
                destLocation.AccessCondition = options.DestinationAccessCondition;
            }

            return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken);
        }