.Net core API 读取文件并拷贝到指定目录

        public IActionResult UploadReportLogo([FromForm,Required] IFormFile file)
        {
            if (file == null || file.Length == 0)
                return BadRequest("Can not find file");

            string logoPath = Path.Combine(Directory.GetCurrentDirectory(), Settings.STATIC_FOLDER_LOGO).ToString();
            Stream stream = file.OpenReadStream();
            //byte[] bytes = new byte[stream.Length];
            //stream.Read(bytes, 0, bytes.Length);
            string fileName = file.FileName;
            Stream writeTo = System.IO.File.Create(logoPath+ fileName);
            stream.CopyTo(writeTo);
            writeTo.Dispose();
            return Ok("Success");
        }

  

 

posted @ 2022-03-14 15:56  Aaron_M  阅读(483)  评论(0编辑  收藏  举报