[英]Uploading file IFormFile to Azure C# function
I have this regular C# Azure function:我有这个常规的 C# Azure function:
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log) ...
And I need to upload here file, eg image.我需要在这里上传文件,例如图片。 How can I add here IFormFile
or is there other way to upload file to function?如何在此处添加IFormFile
或有其他方式将文件上传到 function?
To upload a file to an Azure Function, have a look at the Form of the incoming HttpRequest
.要将文件上传到 Azure Function,请查看传入HttpRequest
的表单。
This works for me:这对我有用:
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "files")] HttpRequest req,
ILogger log)
{
foreach(var file in req.Form.Files)
{
using (var ms = new MemoryStream())
{
var file = req.Form.Files[0];
await file.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
// Do something with the file
}
}
return new OkResult();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.