2

我有这个常规的 C# Azure 函数:

[FunctionName("Function1")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log) ...

我需要在这里上传文件,例如图片。我如何在此处添加IFormFile或是否有其他方法可以上传文件以发挥作用?

4

1 回答 1

2

要将文件上传到 Azure 函数,请查看传入的HttpRequest.

这对我有用:

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();
}
于 2020-05-14T14:04:59.870 回答