問題我試圖通過Amazon S3已經爲我生成的PUT請求URL發送文件到S3。C#HTTP PUT請求代碼
我的代碼適用於小文件,但在發送幾分鐘後出現大文件(> 100 MB)時出錯。
出現錯誤的是:請求被中止:請求被取消。在System.Net.ConnectStream.Write(Byte []緩衝區,Int32偏移量,Int32大小)上的System.Net.ConnectStream.InternalWrite(布爾異步,字節[]緩衝區,Int32偏移量,Int32大小,AsyncCallback回調,對象狀態)
有人可以告訴我什麼是我的代碼是阻止它發送大文件的錯誤嗎?這不是由於Amazon PUT請求URL過期導致的,因爲我已將該設置設置爲30分鐘,並且在發送幾分鐘後出現問題。
的代碼最終例外出來這行代碼:dataStream.Write(byteArray, 0, byteArray.Length);
再次,它的偉大工程,我發送給S3較小的文件。只是不大的文件。
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
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();
// this is the line of code that it eventually quits on.
// Works fine for small files, not for large ones
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//This will return "OK" if successful.
WebResponse response = request.GetResponse();
Console.WriteLine("++ HttpWebResponse: " +
((HttpWebResponse)response).StatusDescription);
這可能很明顯,但您確定亞馬遜的S3服務允許超過100MB的HTTP請求嗎? – Icarus
我不認爲這是問題。完整的100MB永遠不會被髮送(它會在一兩分鐘後停止)。我可以使用任何第三方S3軟件程序發送文件,並通過PUT請求發送它,並且工作正常。我認爲除了S3的問題之外,我的代碼有問題。 – fraXis
在上面的代碼中,您的超時時間僅爲6分鐘,而不是30分。 –