public override async Task <Message> BeforeMessageSend(Message message)
        {
            if (AttachmentBlobAssociated(message.UserProperties))
            {
                return(message);
            }

            if (!configuration.MessageMaxSizeReachedCriteria(message))
            {
                return(message);
            }

            var containerUri = new Uri($"{configuration.BlobEndpoint}{configuration.ContainerName}");
            var container    = new CloudBlobContainer(containerUri, configuration.StorageCredentials);

            try
            {
                // Will only work for Shared Key or Account SAS. For Container SAS will throw an exception.
                if (!await container.ExistsAsync().ConfigureAwait(false))
                {
                    await container.CreateIfNotExistsAsync().ConfigureAwait(false);
                }
            }
            catch (StorageException)
            {
                // swallow in case a container SAS is used
            }

            var blobUri = new Uri($"{containerUri}/{Guid.NewGuid().ToString()}");
            var blob    = new CloudBlockBlob(blobUri, configuration.StorageCredentials);

            SetValidMessageId(blob, message.MessageId);
            SetValidUntil(blob, message.TimeToLive);

            await blob.UploadFromByteArrayAsync(message.Body, 0, message.Body.Length).ConfigureAwait(false);

            message.Body = null;
            message.UserProperties[configuration.MessagePropertyToIdentifyAttachmentBlob] = blob.Name;

            if (!configuration.BlobSasTokenValidationTime.HasValue)
            {
                return(message);
            }

            // TODO: only possible if connection string is used
            // configuration.StorageCredentials.IsSharedKey
            var sasUri = TokenGenerator.GetBlobSasUri(blob, configuration.BlobSasTokenValidationTime.Value);

            message.UserProperties[configuration.MessagePropertyForBlobSasUri] = sasUri;
            return(message);
        }
        public override async Task <Message> BeforeMessageSend(Message message)
        {
            ThrowIfDisposed();

            if (AttachmentBlobAssociated(message.UserProperties))
            {
                return(message);
            }

            if (!configuration.MessageMaxSizeReachedCriteria(message))
            {
                return(message);
            }

            await InitializeClient().ConfigureAwait(false);

            var container = client.GetContainerReference(configuration.ContainerName);

            if (!await container.ExistsAsync().ConfigureAwait(false))
            {
                await container.CreateIfNotExistsAsync().ConfigureAwait(false);
            }
            var blob = container.GetBlockBlobReference(Guid.NewGuid().ToString());

            SetValidMessageId(blob, message.MessageId);
            SetValidUntil(blob, message.TimeToLive);

            await blob.UploadFromByteArrayAsync(message.Body, 0, message.Body.Length).ConfigureAwait(false);

            message.Body = null;
            message.UserProperties[configuration.MessagePropertyToIdentifyAttachmentBlob] = blob.Name;

            if (!configuration.SasTokenValidationTime.HasValue)
            {
                return(message);
            }

            var sasUri = TokenGenerator.GetBlobSasUri(blob, configuration.SasTokenValidationTime.Value);

            message.UserProperties[configuration.MessagePropertyForSasUri] = sasUri;
            return(message);
        }