티스토리 뷰

💼 정보 ver1.0

4M이상 파일 업로드하기.

James Wetzel 2012. 4. 10. 11:47

private string fileUpload()

    {

       

        string filePath = System.Web.Configuration.WebConfigurationManager.AppSettings["mediaFilePath"].ToString();

        string fileNames = string.Empty;

        HttpFileCollection hfc = Request.Files;


        foreach (string k in hfc.AllKeys)

        {

            if (hfc[k].ContentLength > 0 && hfc[k].ContentLength <= 8000000)            

            {

                hfc[k].SaveAs(filePath + "\\" + hfc[k].FileName);

                fileNames += hfc[k].FileName + "|";

            }

            else

            {

                Response.Write("파일 사이즈가 너무 크군요.");

            }

        }

        

        return fileNames;

    }


machine.config 파일에 의해 기본값으로 4096KB로 업로드 파일이 제한되어 있다.

web.config 파일<system.web> 아래에<httpRuntime maxRequestLength="205300" executionTimeout="6000"/>을 추가한다.


Tip]

maxRequestLength="205300"(약 200MB)로 설정했다 만약 200MB보다 작은 파일이 업로드 된다면 

"Response.Write("파일 사이즈가 너무 크군요.")"가 정상적으로 동작을 하지만, 200MB 보다 더 큰 파일이 업로드된다면

 ASP.NET은 페이지를 만료시켜 버린다. 아마 보안을 위해서 그렇게 하지않았나 싶다.

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함