【发布时间】:2020-05-07 15:00:54
【问题描述】:
我在 .Net Core 中有一项服务,它以 IFormFile 作为参数。我想将此 IFormFile 中的数据发送到 Api。下面的代码是邮递员自动生成的代码,适用于我的请求。在'attachmentRequest.AddFile("file", file);'行,文件是邮递员上传文件的本地路径的字符串。将我的 IFormfile 作为文件发送的最佳方式是什么?我是否使用流并将 IFormfile 保存到 .Net Core 中的某个位置并传递该地址?
public async Task<bool> PostIssue(IFormFile file)
{
var client = new RestClient("https://sample/10000/attachments");
client.Timeout = -1;
var attachmentRequest = new RestRequest(Method.POST);
attachmentRequest.AddHeader("X-Atlassian-Token", "no-check");
attachmentRequest.AddHeader("Authorization", "Basic xxxxxxxxxxxxxx=");
attachmentRequest.AddHeader("Cookie", "atlassian.xsrf.token=xxxxxxxxxxxxxxxxxx_lin");
attachmentRequest.AddFile("file", file);
IRestResponse attachmentResponse = client.Execute(attachmentRequest);
Console.WriteLine(attachmentResponse.Content);
if (attachmentResponse.IsSuccessful)
{
return true;
}
else
{
return false;
}
}
【问题讨论】:
标签: c# asp.net-core stream postman