본문 바로가기
Programming/.NET

[.NET Core] wwwroot 폴더 밖에 있는 file download

by 째스터 2022. 10. 19.
728x90

wwwroot 폴더 밖에 있는 파일을 download 해야 하는 경우가 있다.
그럴 땐 아래와 같이 PhysicalFile() 를 통해 PhysicalFileResult 를 리턴하면 된다.

return PhysicalFile(filePath, contentType);

// [참고] 파일명이 fileName인 첨부파일
return PhysicalFile(filePath, contentType, fileName);

 

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.physicalfile?view=aspnetcore-6.0 

 

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

댓글