은 참조하십시오 : 나는 S3에 파일을 업로드 할 C# WebRequest 클래스 방법을 사용하고 Problem with C# HTTP PUT request codeWebRequest 클래스 - .timeout 질문 좀 더 배경에 대한
. 이미 S3에서 업로드를 위해 제공하는 사전 서명 된 URL이 있습니다. 원래 대용량 파일을 업로드하는 경우 전송이 시작된 후 몇 분 후에 중단됩니다. 내 다른 게시물에 대한 의견은 그것을 일으키는. timeout이라고했습니다. 물론 그랬다.
내 질문은 다음과 같습니다. .timeout을 어떻게 설정해야합니까? 또는 전송할 파일의 크기에 따라 설정할 시간을 어떻게 계산할 수 있습니까?
S3에 작은 파일을 전송할 때 60 분의 시간 제한으로 WebRequest를 시작하고 싶지는 않지만 다시 S3에 기가 바이트 파일을 업로드 할 수 있으며 시간 초과가 발생하면 파일이 완료되기 전에 전송이 중단됩니다.
또한 연결 시간 제한을 설정하려면 어떻게해야합니까? .timeout도 사용됩니까? S3가 내 웹 PUT 요청에 응답하고 시간 초과가 없는지 확인하기 위해 30 초 동안 연결을 시도하려는 경우에는 어떻게해야합니까?
내 코드는 다음과 같습니다
WebRequest request = WebRequest.Create(PUT_URL_FINAL[0]);
//PUT_URL_FINAL IS THE PRE-SIGNED AMAZON S3 URL THAT I AM SENDING THE FILE TO
request.Timeout = 360000; //6 minutes -- If the transfer is over 6 minutes, it stops.
request.Method = "PUT";
//result3 is the filename that I am sending
request.ContentType =
MimeType(GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
Path.DirectorySeparatorChar +
System.Web.HttpUtility.UrlEncode(result3));
byte[] byteArray =
File.ReadAllBytes(
GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
Path.DirectorySeparatorChar +
System.Web.HttpUtility.UrlEncode(result3));
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//This will return "OK" if successful.
WebResponse response = request.GetResponse();
Console.WriteLine("++ HttpWebResponse: " +
((HttpWebResponse)response).StatusDescription);
BTW, 'Stream' 및'WebResponse '객체는 'using '블록 내에 있어야합니다. –