hiFI
hiFI

Reputation: 1961

Triggered Azure Function to Invoke a Webjob

My Requirement:

As soon as a file being uploaded to a Blob Container, the Azure Function is being alerted and withing that Azure Function I want to call a Webjob who uses the uploaded file and does any task.

What I learnt:

I learnt that Azure Function can be triggered when a file being uploaded to a blob container. I tried the tutorials and was able to configure an Azure function and it acts for any change in blob container. I did this via Azure Portal and not used Visual Studio.

Now I want to call a WebJob within the Azure Function. Please help me on this.

Upvotes: 1

Views: 1577

Answers (1)

kgalic
kgalic

Reputation: 2654

Assuming that you have written your function in C#, below is the code that might help you. Essentially the idea is to send a POST request to trigger your job:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(“https://your_web_site.azurewebsites.net/api/”);
var byteArray = Encoding.ASCII.GetBytes(“your_username:your_password”);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray));  
var response = await client.PostAsync(“triggeredwebjobs/your_web_job_name/run”, null);

Username and password you find in Azure portal, in the properties of your job.

Upvotes: 1

Related Questions