如何从Logic App发送文件到功能应用程序?

问题描述 投票:1回答:2

我有一个逻辑应用程序,它读取邮件内容及其附件。我需要将文件/文件内容(文件首选)发送到功能App。

后来的功能App与第三方API交互,需要将相同的文件传递给该API。

NB - >我能够在Logic App中获取文件字节。但是在通过Json结构将Bytes传递给函数App时,Json反序列化显示了@function App end的问题。

azure azure-functions azure-logic-apps
2个回答
2
投票

您可以将文件从逻辑应用程序发送到azure函数作为附件content.enter image description here

在Azure功能方面,您可以直接读取它,如下所示:

#r "Newtonsoft.Json"

using System;
using System.Net;
using Newtonsoft.Json;
using System.IO;
using System.Globalization;

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
    {
        try
        {
            log.Info($" my function was triggered!");

            string jsonContent = await req.Content.ReadAsStringAsync();
            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            if (data.fileName == null && string.IsNullOrWhiteSpace(data.fileName))
            {
                return req.CreateResponse(HttpStatusCode.BadRequest, new
                {
                    error = "Invalid json parameters!"
                });
            }
            string fileName = data.fileName;
            var fileData = data.fileContent;
            string val = fileData.ToObject<string>();

            var base64EncodedBytes = System.Convert.FromBase64String(val);
            var result = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
            // log.Info($"file data val : "+result);
            StringReader stringReader = new StringReader(result);
            //rest you can do yourself
        }
        catch (Exception ex)
        {

        }
    }

希望这可以帮助。


1
投票

我会使用Azure Blob Storage作为Logic App和Function App之间的接口。

根据this documentation,在Logic App上可以使用Azure Blob存储标准连接器。可以使用Create Blob动作,它需要您可以检索的文件字节。

功能应用程序可以绑定为特定Azure Blob存储容器的触发器。 Here is an example

[FunctionName("BlobTrigger")]        
public static void Run([BlobTrigger("blobcontainer/{name}", Connection = "StorageConnectionAppSetting")] Stream myBlob, string name, TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
© www.soinside.com 2019 - 2024. All rights reserved.