How to make the input stream content to be copied to the output stream in azure func

Tony Johansson 40 Reputation points
2023-05-15T07:39:08.9733333+00:00

Hello,

I have the following azure function which use imperativ binding. The writer

write json data to the output stream which works fine. Instead of write json data I would rather use the same contents the exist in the input stream which is xml data.

So from the input stream I want to copy the content to the output stream.

public void Run(
            [BlobTrigger("input/{name}.xml")] Stream inputBlob,
            IBinder binder,
            string name, ILogger log)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(inputBlob);

            string json = jsonHandling.Convert(doc);
            json = jsonHandling.Clean(json);

            using (var writer = binder.Bind<TextWriter>(new BlobAttribute(
                    $"output/a6109523-a23b-47ed-9732-40ea4535c82f {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}.json", FileAccess.Write)))
            {
                writer.Write(json);
            };
        }

Many thanks in advance

Tony Johansson

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,512 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,544 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,524 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 13,265 Reputation points
    2023-05-16T13:09:44.3066667+00:00

    I have added a sample code please check if it works for you

    if not I can work on this in more detail

    public void Run(
        [BlobTrigger("input/{name}.xml")] Stream inputBlob,
        IBinder binder,
        string name, ILogger log)
    {
        using (var outputBlob = binder.Bind<Stream>(new BlobAttribute(
            $"output/a6109523-a23b-47ed-9732-40ea4535c82f {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}.xml", FileAccess.Write)))
        {
            inputBlob.CopyTo(outputBlob);
        };
    }
    
    

0 additional answers

Sort by: Most helpful