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.
5,930 questions
Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 14,180 Reputation points MVP
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.