728x90
wwwroot 폴더 밖에 있는 파일을 download 해야 하는 경우가 있다.
그럴 땐 아래와 같이 PhysicalFile() 를 통해 PhysicalFileResult 를 리턴하면 된다.
return PhysicalFile(filePath, contentType);
// [참고] 파일명이 fileName인 첨부파일
return PhysicalFile(filePath, contentType, fileName);
ControllerBase.PhysicalFile Method (Microsoft.AspNetCore.Mvc)
Returns the file specified by physicalPath (Status200OK), the specified contentType as the Content-Type, and the specified fileDownloadName as the suggested file name. This supports range requests (Status206PartialContent or Status416RangeNotSatisfiable if
learn.microsoft.com
728x90
'Programming > .NET' 카테고리의 다른 글
[.NET] Google Gmail SMTP 설정 방법 & 전송 기능 (0) | 2022.11.07 |
---|---|
[.NET Core] Razor 파일 코드 변동사항 바로 적용되도록 설정하기 (0) | 2022.10.26 |
MVC Controller HttpGet, HttpPost Attribute 동시 사용시 주의점 (0) | 2022.06.23 |
[Azure] Azure Storage - Blob Storage (0) | 2022.04.15 |
[.NET] FormData를 이용한 file upload (0) | 2022.03.19 |
댓글