问题
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);
}
}
}
回答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);
}
}
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.
回答2:
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://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/register-custom-api
来源:https://stackoverflow.com/questions/60169520/how-to-implement-my-azure-function-for-using-it-in-powerapps