.net Core 上传图片并保存 非FE
作者:互联网
1、上传图片并保存 本地文件夹
/// <summary> /// 上传 保存图片 /// </summary> /// <returns></returns> [HttpPost] public IActionResult UpLoad() { //http 协议 Request Response //获取文件 var hpf = Request.Form.Files[0]; //新名称 var newFileName = Guid.NewGuid().ToString(); //获取扩展名 var ext = Path.GetExtension(hpf.FileName); //将文件名和扩展名拼接 var newName = newFileName + ext; //找到路径 将虚拟路径转成物理路径 var path = Directory.GetCurrentDirectory() +"/Images"; //合并路径和文件名 var newPath = Path.Combine(path, newName); using (var stream = System.IO.File.Create(newPath)) { hpf.CopyTo(stream); } return Ok(new { url = newName }); }
标签:newPath,Core,newName,路径,FE,var,net,上传,hpf 来源: https://www.cnblogs.com/sjt9/p/15666922.html