0

Im currently trying to write a function to combine two images from azure storage to one image. I dont know how to setup my function class so that I can trigger the function in powerapps with 2 selected images.

This is my class

    public static class Function1
{
    [Obsolete] // switch TraceWrite to Ilogger
    [FunctionName("Function1")]
    public static void Run(string background, string overlay, CloudBlockBlob outputBlob, TraceWriter log)
    {
        log.Info($"Function triggered with blob\n Background: {background} \n Overlay: {overlay}");

        ConvertMe Converter = new ConvertMe(System.Drawing.Color.Black); // My ImageEdit Class I have written
        Bitmap _Main = new Bitmap(background);
        Bitmap Overlay = Converter.MakeTransparent(overlay);



        using (MemoryStream memory = new MemoryStream())
        {
            Converter.ComebineBitmap(_Main, Overlay).Save(memory, ImageFormat.Jpeg);
            memory.Position = 0;
            outputBlob.Properties.ContentType = "image/jpeg";
            outputBlob.UploadFromStreamAsync(memory);
        }


    }

}
wambo
  • 67
  • 1
  • 10
  • So far I know you cannot directly call `Azure Function` from `Power Apps` you can do it using `Microsoft flow` or `logic App`. Steps are, `1.` `Call azure function on logic app or Microsoft flow` `2.` `Bind Power apps with flow or Logic App` – Md Farid Uddin Kiron Feb 11 '20 at 15:06
  • Ok I didnt know this. Do you know how to setup my class for this ? Im new in Azure functions and its a big step between my function and the hello world tutorial function ^^ – wambo Feb 11 '20 at 15:55
  • Did you mean how you could add class on `azure function`? – Md Farid Uddin Kiron Feb 11 '20 at 16:46
  • I meant specially my function above. I dont know how to configurate and setup. Im also not sure if this function works like this. – wambo Feb 11 '20 at 16:49

2 Answers2

1

Firstly, suppose you already know you could not directly call your function, especially you are using blob trigger function.

Then is about how to use function in power apps. There is blog about this: Using Azure Functions in PowerApps. You need the http trigger function and define the REST signature using Swagger then use the custom API in power apps.

The last thing is about how to get two blob in the http trigger function. From the blob binding doc you could get the Input-usage, you could find the c# or c# script function both support CloudBlockBlob binding.

The below is a sample read from two txt blob with http trigger function, you could add an output binding to storage the output image.

public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Blob("test/test.txt",FileAccess.ReadWrite)]CloudBlockBlob blob1,
            [Blob("test/out.txt", FileAccess.ReadWrite)]CloudBlockBlob blob2,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string test = await blob1.DownloadTextAsync();
            string outtxt = await blob2.DownloadTextAsync();
            log.LogInformation("test value: " + test);
            log.LogInformation("outtxt value: " + outtxt);

        }
    }

enter image description here

Then follow the blog, suppose this could work, hope this could help you, if you still have other problem, please feel free to let me know.

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Much appreciation :). Do I have to download my blobs or can i call them by their uri ? why do I need HttpRequest req ? you dont call it. My Goal is to implement my Httptrigger like this "http://azurefn.azurewebsites.net/api/ConvertMe?Image1={Placeholder1}&Image2={Placeholder2}" Placeholder1 = BlobUri1 (Loaded into a variable in PowerApps) Placeholder2 = BlobUri2 (Loaded into a variable in PowerApps). this is my changed Code so far. https://pastebin.com/4fK26wrg – wambo Feb 12 '20 at 09:11
  • Fehler bei Funktion (ConvertMe/ConvertMe): Microsoft.Azure.WebJobs.Host: Error indexing method 'ConvertMe'. Microsoft.Azure.WebJobs.Host: Validation failed for property 'BlobPath', value 'Test'. The field BlobPath is invalid. This is the error I receive after I deploy it to azure (online). – wambo Feb 12 '20 at 09:33
  • 1
    If your code have problem, you should paste you code. From the error it should be your blob path is not correct, did you just deploy my code without any change even your blob path? – George Chen Feb 12 '20 at 09:57
  • 1
    Actually I call the function url, HttpRequest is because it's http trigger function, and about why use http trigger cause you want to use it in power apps. Then `Placeholder1` don't have to be the bloburi it could be just the blob name. And you could bind it to container like this [picture show](https://i.stack.imgur.com/VvbJ8.png). – George Chen Feb 12 '20 at 10:04
  • Hmh I think I might doing something wrong or misunderstanding something. I think my code isnt wrong. Im gonna try this with blobcontainers after I know how to publish this code to azure function in without getting errors. ^^ this is my function.cs https://pastebin.com/KXFu72UH – wambo Feb 12 '20 at 10:31
  • 1
    I have to remind you one more thing, from your code suppose you are using `System.Drawing`, and this is not support by azure function. Check this.https://stackoverflow.com/a/51907024/10383250 – George Chen Feb 12 '20 at 10:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/207653/discussion-between-wambo-and-george-chen). – wambo Feb 12 '20 at 10:49
  • 1
    @wambo, any update on this issue? If this could help you, please accept it as the answer. – George Chen Feb 13 '20 at 09:54
0

If you make the function triggered via HTTP, you can use a Custom API connection in Power Apps to connect to your API and send/request data etc.

You will need to deploy your function somewhere preferably Azure.

https://powerapps.microsoft.com/es-es/blog/register-and-use-custom-apis-in-powerapps/

https://powerapps.microsoft.com/uk-ua/blog/building-a-custom-api-for-powerapps-using-azure-app-service-web-apps/

https://learn.microsoft.com/en-us/powerapps/maker/canvas-apps/register-custom-api

Chris
  • 3,113
  • 5
  • 24
  • 46