C# Azure功能无法正常工作?
我有一个azure函数,它接受一个使用多表单的输入文件,如下所示-C# Azure功能无法正常工作?,c#,azure,http,powerapps,C#,Azure,Http,Powerapps,我有一个azure函数,它接受一个使用多表单的输入文件,如下所示- public static class function { [FunctionName("Function1")] public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage
public static class function
{
[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log,string imagename)
{
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
log.Info("C# HTTP trigger function processed a request.");
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
我已经正确配置了Auth0,但是当我尝试在Powerapps中运行它时,它返回未知错误作为响应
我正在尝试将图像发送到azure函数,并希望使用该函数将其转换为PDF。我该怎么做 根据您的代码,您似乎正在使用。我发现您的HttpTrigger函数代码与您提供的swagger文件不匹配。简单来说,我只是使用Azure门户并创建了我的HttpTrigger函数,如下所示: run.csx:
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage request, TraceWriter log)
{
//Check if the request contains multipart/form-data.
if (!request.Content.IsMimeMultipartContent())
{
return request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
//The root path where the content of MIME multipart body parts are written to
string root = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), @"site\wwwroot\HttpTriggerCSharp1\");
var provider = new MultipartFormDataStreamProvider(root);
// Read the form data
await request.Content.ReadAsMultipartAsync(provider);
List<UploadedFileInfo> files = new List<UploadedFileInfo>();
// This illustrates how to get the file names.
foreach (MultipartFileData file in provider.FileData)
{
var fileInfo = new FileInfo(file.Headers.ContentDisposition.FileName.Trim('"'));
files.Add(new UploadedFileInfo()
{
FileName = fileInfo.Name,
ContentType = file.Headers.ContentType.MediaType,
FileExtension = fileInfo.Extension,
FileURL = file.LocalFileName
});
}
return request.CreateResponse(HttpStatusCode.OK, files, "application/json");
}
public class UploadedFileInfo
{
public string FileName { get; set; }
public string FileExtension { get; set; }
public string FileURL { get; set; }
public string ContentType { get; set; }
}
使用System.Net;
公共静态异步任务运行(HttpRequestMessage请求、TraceWriter日志)
{
//检查请求是否包含多部分/表单数据。
如果(!request.Content.IsMimeMultipartContent())
{
返回请求.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
//MIME多部分正文部分内容写入的根路径
字符串root=Path.Combine(System.Environment.GetEnvironmentVariable(“HOME”),@“site\wwwroot\HttpTriggerCSharp1\”;
var provider=新的MultipartFormDataStreamProvider(根);
//读取表单数据
wait request.Content.ReadAsMultipartAsync(提供程序);
列表文件=新列表();
//这说明了如何获取文件名。
foreach(provider.FileData中的MultipartFileData文件)
{
var fileInfo=newfileinfo(file.Headers.ContentDisposition.FileName.Trim(“”);
添加(新上载的fileinfo()
{
FileName=fileInfo.Name,
ContentType=file.Headers.ContentType.MediaType,
FileExtension=fileInfo.Extension,
FileURL=file.LocalFileName
});
}
return request.CreateResponse(HttpStatusCode.OK,文件,“application/json”);
}
公共类UploadedFileInfo
{
公共字符串文件名{get;set;}
公共字符串文件扩展名{get;set;}
公共字符串FileURL{get;set;}
公共字符串ContentType{get;set;}
}
注意:MIME多部分身体部位存储在您的temp文件夹下。您可以通过file.LocalFileName
检索temp文件完整路径,然后使用相关库处理转换,然后保存PDF文件并删除temp文件,然后将转换后的文件返回给客户端
测试:
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage request, TraceWriter log)
{
//Check if the request contains multipart/form-data.
if (!request.Content.IsMimeMultipartContent())
{
return request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
//The root path where the content of MIME multipart body parts are written to
string root = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), @"site\wwwroot\HttpTriggerCSharp1\");
var provider = new MultipartFormDataStreamProvider(root);
// Read the form data
await request.Content.ReadAsMultipartAsync(provider);
List<UploadedFileInfo> files = new List<UploadedFileInfo>();
// This illustrates how to get the file names.
foreach (MultipartFileData file in provider.FileData)
{
var fileInfo = new FileInfo(file.Headers.ContentDisposition.FileName.Trim('"'));
files.Add(new UploadedFileInfo()
{
FileName = fileInfo.Name,
ContentType = file.Headers.ContentType.MediaType,
FileExtension = fileInfo.Extension,
FileURL = file.LocalFileName
});
}
return request.CreateResponse(HttpStatusCode.OK, files, "application/json");
}
public class UploadedFileInfo
{
public string FileName { get; set; }
public string FileExtension { get; set; }
public string FileURL { get; set; }
public string ContentType { get; set; }
}
此外,我建议您将文件存储在下。您可以向该官员咨询开始使用该文件的信息。在不了解您收到的错误消息的任何详细信息的情况下,我建议您阅读以下问题:它可能与您如何从请求主体获取文件有关。