Reputation: 1158
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?
Upvotes: 0
Views: 567
Reputation: 6816
I think you can use the following parameter types, you can refer to this documentation:
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:
Upvotes: 1