Azure – automating events based on new blob storage file triggers

I’m looking into automating some stuff in Azure and wanted to ask for tips.
The invironment: a VM that creates some local db backups, then sends them via azcopy to Blob Storage.
The goal: each time the the backup is copied to Blob Storage I want to test its correctness, so:
– power on an already prepared another db VM – copy the backup file from Blob Storage
– import it to the db VM
– do some checks
– shut down the db VM
– restore it to its previous state
– send a report if checks failed
From my reasearch it seems that I could utilise either Event Hub or Data Factory, both together with Azure Functions.
Which way would you recommend and what steps should I take (ie. create Data Factory event, make it react on trigger, create a pipeline with additional steps)? I’m a bit overwhelmed with all the options there are out there. Anyway, many thanks in advance!

sending an AJAX request for an audio blob to an async API

I’m working on a legacy system and I’m trying to call an HTTP handler which I have added some logic which retrieves audio blob from an Azure service. The thing is, I can’t seem to get the content back to the client so I can play it. The response that I get from a jQuery call is: “System.Threading.Tasks.Task`1[System.String]”

This is the processRequest code:

public void ProcessRequest(HttpContext context)     {         var text = "walk";         Authentication auth = new Authentication("subscriptionID");         context.Response.Write(auth.getVoice(text));     } 

Here’s the getVoice function:

 public async Task<string> getVoice(string text)     {         using (var client = new HttpClient())         {             try             {                 client.DefaultRequestHeaders                     .Add("User-Agent", "uagent");                 client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);                 client.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.token);                 client.DefaultRequestHeaders.Add("host", "westeurope.tts.speech.microsoft.com");                 client.DefaultRequestHeaders.Add("X-MICROSOFT-OutputFormat", "audio-16khz-32kbitrate-mono-mp3");                 UriBuilder uriBuilder = new UriBuilder(VoiceUri);                 // send xml post                  var voiceTest = "<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female'\n\rname='Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'>\n\rWalk\n\r</voice></speak>";                 var data = new StringContent(voiceTest, Encoding.UTF8, "application/xml");                 data.Headers.ContentType = new MediaTypeHeaderValue("application/ssml+xml");                 var result = await client.PostAsync(uriBuilder.Uri.AbsoluteUri, data);                 return await result.Content.ReadAsStringAsync();             }             catch (Exception e)             {                  return null;             }         } 

The server API call is successful but I can’t seem to receive it on the client side in order to play it to the user afterward.

How to import Azure blob file into Sql Server 2008

Is there a way to import Blob files into sql server 2008 other than using CLR ?

The file size is around 300MB so CLR isn’t efficient enough. Is there a possibility to use BULK INSERT or OPENROWSET in 2008 server?

Example in Sql Server 2017 we can do this

CREATE DATABASE SCOPED CREDENTIAL AzureDevBlobImportCred WITH IDENTITY = 'SHARED ACCESS SIGNATURE', SECRET = 'st=2018-12-05T.....'  go  CREATE EXTERNAL DATA SOURCE AzureDevBlobImportExternalSrc WITH  (     TYPE = BLOB_STORAGE,     LOCATION = 'https://myStorageAccount.blob.core.windows.net', -- storage account URL     CREDENTIAL = AzureDevBlobImportCred -- External Data Source ); 

then we can use the external data source in bulk import

BULK INSERT #Mytemptable  FROM 'filename' WITH (DATA_SOURCE = 'AzureDevBlobImportExternalSrc' );  

So do we have something like above to import blob files in Sql Server 2008 ?

Multiple HTML5 Video Source Blob URL Uploading

I am trying video uploading.But first user can preview the video and then upload it.The problem is multiple BLOB Url uploading via ajax and getting file as List HttpPostedFileBase .I am using ASP.NET MVC.

                    var $  source = $  ('#' + id);                     var reader = new FileReader();                     reader.readAsDataURL(this.files[0]);                     reader.onloadend = (function() {                     $  source[0].src = reader.result;                     $  source.parent()[0].load(); 

Is it possible to create a blob triggered azure function with file name pattern?

I am developing a blob triggered azure function. Following is the configuration of my “function.json” file:

{   "disabled": false,   "bindings": [     {       "name": "myBlob",       "type": "blobTrigger",       "direction": "in",       "path": "input/{name}",       "connection": "BlobConnectionString"     }   ] } 

My function is working fine. It is triggered for all files in “input” blob. Now I want to filter files by its naming pattern. For Example : I want to trigger my azure function for only those files which contains “~123~” in its name.

Is it possible to do with some change in “path” property of “function.json” file? If yes, then what should be the value of the “path” property?

Thanks,

Azure Blob and Table storage rewriting the code in a more simple way

I wrote this code, but is not very practical. I’m still new in this area of coding. Basically I’m storing an image into a blob container, and i’m saving the url in a table. I’m doing the same thing for a text file. So i would like to use dependency injection for azure connection part to make my code more practical.

Here’s my Logo Controller.

[Route("api/manage/logo")] [ApiController]  public class ManageLogoController : ControllerBase {      [HttpPost("{version}")]     public async Task<IActionResult> Post(IFormFile image, float version)     {         if (image.Length >= 1048576)         {             return BadRequest("Uploaded image may not exceed 1Mb, please upload a smaller image.");         }          var allowedExtensions = new[] {             ".png", ".jpg", "jpeg" };         string fileExt = Path.GetExtension(image.FileName);         if (allowedExtensions.Contains(fileExt))         {             try             {                 await LogoStorage.UploadFileToBlobStorage(version, image.FileName);                 return Ok(new                 {                     lenght = image.Length,                     name = image.FileName                 });             }             catch (Exception ex)             {                 return BadRequest();             }         } 

TnC Controller

[Route("api/manage/tnc")] [ApiController]  public class ManageTermCondController : ControllerBase {  [HttpPost("{version}")] public async Task<IActionResult> Post(IFormFile doc, float version) {      var allowedExtension = ".txt";     string fileExt = Path.GetExtension(doc.FileName);     if (allowedExtension.Contains(fileExt))     {         try         {             await TncStorage.UploadDocToBlobStorage(version, doc.FileName);             return Ok(new             {                 lenght = doc.Length,                 name = doc.FileName             });         }         catch (Exception ex)         {             return BadRequest();         }     }      else     {         return BadRequest("Only .txt files are allowed!");     } }    [HttpGet] public string Geti(float version) {     var x = TncStorage.GetURL(version);     if (x == null)     {         return "There's no such record";     }     else return TncStorage.GetURL(version);  } } 

I made a new class library named .Service for the following part.

 public class VersionURL : TableEntity         {             public VersionURL(string type, string version)             {                 PartitionKey = type;                 RowKey = version;             }             public VersionURL() { }             public string URL { get; set; }             public string ETag { get; set; }       } 

First class.

public static async Task UploadFileToBlobStorage(float version, string filename) {     CloudStorageAccount storageAccount = null;     CloudBlobContainer cloudBlobContainer = null;     string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=logodata;AccountKey=p+lksYbHm7vCBIzsuNB9NnoNYP6AYhS56tLkMloZLjRCur8qh5gR/GrkYpV8Egzac3I8r+u9J2xWrEiOXeN+Zg==;EndpointSuffix=core.windows.net";      if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))     {         try         {              CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();             cloudBlobContainer = cloudBlobClient.GetContainerReference("logodata");             await cloudBlobContainer.CreateIfNotExistsAsync();             BlobContainerPermissions permissions = new BlobContainerPermissions             {                 PublicAccess = BlobContainerPublicAccessType.Blob             };             await cloudBlobContainer.SetPermissionsAsync(permissions);              var blobUrl = "";             string file = Guid.NewGuid().ToString() + Path.GetExtension(filename);             CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(file);             try             {                 await cloudBlockBlob.UploadFromFileAsync(filename);              }             catch (Exception ex)             {              }             blobUrl = cloudBlockBlob.Uri.AbsoluteUri;               CloudTableClient tableClient = storageAccount.CreateCloudTableClient();             CloudTable table = tableClient.GetTableReference("CommonURL");             await table.CreateIfNotExistsAsync();              var v = "v" + version;             VersionURL content = new VersionURL("Logo", v);             content.ETag = "*";             content.URL = blobUrl;             var query = new TableQuery<VersionURL>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, v));             TableContinuationToken continuationToken = null;             do             {                 var result = await table.ExecuteQuerySegmentedAsync(query, continuationToken);                 continuationToken = result.ContinuationToken;                  if (result.Count() != 0)                 {                     foreach (VersionURL entity in result)                     {                         if (entity.RowKey == v)                         {                             try                             {                                 TableOperation updateOperation = TableOperation.Merge(content);                                 await table.ExecuteAsync(updateOperation);                             }                             catch (Exception ex)                             {                              }                         }                      }                 }                 else                 {                     TableOperation insertOperation = TableOperation.Insert(content);                     await table.ExecuteAsync(insertOperation);                 }             } while (continuationToken != null);         }         catch (StorageException ex)         {             Console.WriteLine("Error returned from the service: {0}", ex.Message);         }         finally         {          }     }     else     {         Console.WriteLine(             "A connection string has not been defined in the system environment variables. " +             "Add a environment variable named 'storageconnectionstring' with your storage " +             "connection string as a value.");     } }     } 

The second class.

  public class TncStorage     {  public static async Task UploadDocToBlobStorage(float version, string filename) {     CloudStorageAccount storageAccount = null;     CloudBlobContainer cloudBlobContainer = null;     string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=logodata;AccountKey=p+lksYbHm7vCBIzsuNB9NnoNYP6AYhS56tLkMloZLjRCur8qh5gR/GrkYpV8Egzac3I8r+u9J2xWrEiOXeN+Zg==;EndpointSuffix=core.windows.net";      if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))     {         try         {              CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();             cloudBlobContainer = cloudBlobClient.GetContainerReference("tncdata");             await cloudBlobContainer.CreateIfNotExistsAsync();             BlobContainerPermissions permissions = new BlobContainerPermissions             {                 PublicAccess = BlobContainerPublicAccessType.Blob             };             await cloudBlobContainer.SetPermissionsAsync(permissions);              var blobUrl = "";             string file = Guid.NewGuid().ToString() + Path.GetExtension(filename);             CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(file);             try             {                 await cloudBlockBlob.UploadFromFileAsync(filename);              }             catch (Exception ex)             {              }             blobUrl = cloudBlockBlob.Uri.AbsoluteUri;               CloudTableClient tableClient = storageAccount.CreateCloudTableClient();             CloudTable table = tableClient.GetTableReference("CommonURL");             await table.CreateIfNotExistsAsync();             var v = "v" + version;             VersionURL content = new VersionURL("TnC", v);             content.ETag = "*";             content.URL = blobUrl;             var query = new TableQuery<VersionURL>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, v));             TableContinuationToken continuationToken = null;             do             {                 var result = await table.ExecuteQuerySegmentedAsync(query, continuationToken);                 continuationToken = result.ContinuationToken;                  if (result.Count() != 0)                 {                     foreach (VersionURL entity in result)                     {                         if (entity.RowKey == v)                         {                             try                             {                                  var dec = version + .1;                                 content.RowKey = "v" + dec;                                 TableOperation updateOperation = TableOperation.Insert(content);                                 await table.ExecuteAsync(updateOperation);                               }                             catch (Exception ex)                             {                              }                         }                      }                 }                 else                 {                     TableOperation insertOperation = TableOperation.Insert(content);                     await table.ExecuteAsync(insertOperation);                 }             } while (continuationToken != null);         }         catch (StorageException ex)         {             Console.WriteLine("Error returned from the service: {0}", ex.Message);         }         finally         {          }     }     else     {         Console.WriteLine(             "A connection string has not been defined in the system environment variables. " +             "Add a environment variable named 'storageconnectionstring' with your storage " +             "connection string as a value.");     } }   public static string GetURL(float version) {     CloudStorageAccount storageAccount = null;     string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=logodata;AccountKey=p+lksYbHm7vCBIzsuNB9NnoNYP6AYhS56tLkMloZLjRCur8qh5gR/GrkYpV8Egzac3I8r+u9J2xWrEiOXeN+Zg==;EndpointSuffix=core.windows.net";     storageAccount = CloudStorageAccount.Parse(storageConnectionString);     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();     CloudTable table = tableClient.GetTableReference("CommonURL");     var v = "v" + version;     var tableQuery = new TableQuery<VersionURL>();     tableQuery = new TableQuery<VersionURL>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, v));     var entities = table.ExecuteQuerySegmentedAsync(tableQuery, null);     var results = entities.Result;     var s = "";     foreach (var file in results.Where(x => x.RowKey == v))     {         //if (file.RowKey == v)         //{         return s = file.URL;          //}         //else         //    return null;     }      return null; } 

Can i make the first and the second class more simple?