4 回复
感谢大家,不吝赐教,还给个demo。
开发用花生壳,返代,报错400.
无奈找了个云服务,测试了下,完全ok。
这里贴一下netcore demo吧
[HttpPost]
[Route("postfile")]
public string UploadAsync()
{
try
{
var files = HttpContext.Request.Form.Files;
if (files.Count < 0)
return "失败";
foreach (var formFile in files)
{
var filePath = @"C:\1\" + formFile.FileName.Substring(formFile.FileName.LastIndexOf("\\") + 1);
if (formFile.Length > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
formFile.CopyToAsync(stream);
}
}
}
return "成功";
}
catch (Exception ex)
{
return "失败2";
}
}