0

I have an Azure HttpTrigger function that use and IBinder to write data to a blob. It works fine for text data that's posted to my function but binary data not valid when written to the blob. I have code similar to what I've seen in other posts and blogs writing, e.g.

public static async Task<IActionResult> Run(
   [HttpTrigger(AuthorizationLevel.Function, "post", Route = "FileDelivery")] HttpRequest httpRequest,
   IBinder myBinder,
   ILogger log)


...

    using (var writer = myBinder.Bind<TextWriter>(new BlobAttribute(
        $"my-files/{filename}", FileAccess.Write)))
        {
            await writer.WriteAsync(await new StreamReader(httpRequest.Body).ReadToEndAsync());
        };

I think the problem is in the TextWriter being used to bind to the blob. I tried to use a BinaryWriter but got the error Can't bind Blob to type 'System.IO.BinaryWriter. No post I've found has described saving binary data to a blob in this way. Is there a blob attribute I'm missing or some other setting that will get this to work?

1 Answer 1

1

I think you can use the following parameter types, you can refer to this documentation:

enter image description here

The following code is an example of how I accept an image and upload it to storage:

            using (var destinationStream = myBinder.Bind<Stream>(new BlobAttribute(
                $"test/test.jpg", FileAccess.Write)))
                {
                var image = req.Form.Files["test"];
                await image.CopyToAsync(destinationStream);
                };

This is my request body:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.