UploadBlob() public method

public UploadBlob ( Uri url, string name, Stream stream, Microsoft.WindowsAzure.MediaServices.Client.FileEncryption fileEncryption, CancellationToken cancellationToken, Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient client, IRetryPolicy retryPolicy, string contentType = null, string subDirectory = "", Func getSharedAccessSignature = null, int parallelTransferThreadCount = 10, int numberOfConcurrentTransfers = default(int) ) : Task
url System.Uri
name string
stream Stream
fileEncryption Microsoft.WindowsAzure.MediaServices.Client.FileEncryption
cancellationToken System.Threading.CancellationToken
client Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient
retryPolicy IRetryPolicy
contentType string
subDirectory string
getSharedAccessSignature Func
parallelTransferThreadCount int
numberOfConcurrentTransfers int
return Task
Esempio n. 1
0
		/// <summary>
		/// Uploads file to a blob storage.
		/// </summary>
		/// <param name="url">The URL where file needs to be uploaded.If blob has private write permissions then appropriate sas url need to be passed</param>
		/// <param name="localFile">The full path of local file.</param>
		/// <param name="fileEncryption">The file encryption if file needs to be stored encrypted. Pass null if no encryption required</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <param name="client">The client which will be used to upload file. Use client if request need to be signed with client credentials. When upload performed using Sas url,
		/// then client can be null</param>
		/// <param name="retryPolicy">The RetryPolicy delegate returns a ShouldRetry delegate, which can be used to implement a custom retry policy.RetryPolicies class can bee used to get default policies</param>
		/// <param name="contentType">Content type of the blob</param>
		/// <param name="subDirectory">Virtual subdirectory for this file in the blog container.</param>
        /// <param name="getSharedAccessSignature">A callback function which returns Sas signature for the file to be downloaded</param>
		/// <returns></returns>
		public virtual Task UploadBlob(
			Uri url, 
			string localFile, 
			FileEncryption fileEncryption, 
			CancellationToken cancellationToken, 
			CloudBlobClient client, 
			IRetryPolicy retryPolicy,
			string contentType = null,
			string subDirectory = "",
			Func<string> getSharedAccessSignature = null
            )
		{

			if (_forceSharedAccessSignatureRetry != TimeSpan.Zero)
			{
				// The following sleep is for unit test purpose and we will force the shared access signature to expire and hit retry code path
				Thread.Sleep(_forceSharedAccessSignatureRetry);
			}

			BlobUploader blobuploader = new BlobUploader(new MemoryManagerFactory());

			blobuploader.TransferCompleted += (sender, args) =>
			{
				if (TransferCompleted != null)
				{
					TransferCompleted(sender, args);
				}
				else if (args.Error != null)
				{
					throw args.Error;
				}
			};

			blobuploader.TransferProgressChanged += (sender, args) =>
			{
				if (TransferProgressChanged != null)
				{
					TransferProgressChanged(sender, args);
				}
			};

		    return blobuploader.UploadBlob(
		        url,
		        localFile,
		        fileEncryption,
		        cancellationToken,
		        client,
		        retryPolicy,
		        contentType,
		        subDirectory,
		        getSharedAccessSignature: getSharedAccessSignature,
		        parallelTransferThreadCount: ParallelTransferThreadCount,
		        numberOfConcurrentTransfers: NumberOfConcurrentTransfers);
		}
        /// <summary>
        /// Uploads file to a blob storage.
        /// </summary>
        /// <param name="url">The URL where file needs to be uploaded.If blob has private write permissions then appropriate sas url need to be passed</param>
        /// <param name="localFile">The full path of local file.</param>
        /// <param name="fileEncryption">The file encryption if file needs to be stored encrypted. Pass null if no encryption required</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="client">The client which will be used to upload file. Use client if request need to be signed with client credentials. When upload performed using Sas url,
        /// then client can be null</param>
        /// <param name="retryPolicy">The RetryPolicy delegate returns a ShouldRetry delegate, which can be used to implement a custom retry policy.RetryPolicies class can bee used to get default policies</param>
        /// <param name="contentType">Content type of the blob</param>
        /// <param name="subDirectory">Virtual subdirectory for this file in the blog container.</param>
        /// <param name="getSharedAccessSignature">A callback function which returns Sas signature for the file to be downloaded</param>
        /// <returns></returns>
        public virtual Task UploadBlob(
			Uri url, 
			string localFile, 
			FileEncryption fileEncryption, 
			CancellationToken cancellationToken, 
			CloudBlobClient client, 
			IRetryPolicy retryPolicy,
			string contentType = null,
			string subDirectory = "",
			Func<string> getSharedAccessSignature = null
            )
        {
            if (_forceSharedAccessSignatureRetry != TimeSpan.Zero)
            {
                // The following sleep is for unit test purpose and we will force the shared access signature to expire and hit retry code path
                Thread.Sleep(_forceSharedAccessSignatureRetry);
            }

            BlobUploader blobuploader = new BlobUploader(new MemoryManagerFactory());

            blobuploader.TransferCompleted += (sender, args) =>
            {
                if (TransferCompleted != null)
                {
                    TransferCompleted(sender, args);
                }
                else if (args.Error != null)
                {
                    throw args.Error;
                }
            };

            blobuploader.TransferProgressChanged += (sender, args) =>
            {
                if (TransferProgressChanged != null)
                {
                    TransferProgressChanged(sender, args);
                }
            };

            return blobuploader.UploadBlob(
                url,
                localFile,
                fileEncryption,
                cancellationToken,
                client,
                retryPolicy,
                contentType,
                subDirectory,
                getSharedAccessSignature: getSharedAccessSignature,
                parallelTransferThreadCount: ParallelTransferThreadCount,
                numberOfConcurrentTransfers: NumberOfConcurrentTransfers);
        }