![](/img/trans.png)
[英]Posting a large file via HTTP/REST in C# without loading file into memory
[英]Put large file to one drive with REST api via c#
我想通過rest api將一個大文件(1.4 gb)放到onedrive。
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myUri);
webRequest.Timeout = 12 * 60 * 60 * 1000;
webRequest.AllowAutoRedirect = true;
webRequest.ReadWriteTimeout = 12 * 60 * 60 * 1000;
webRequest.AllowReadStreamBuffering = false;
webRequest.AllowWriteStreamBuffering = false;
webRequest.SendChunked = true;
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.ServicePoint.ConnectionLimit = 1;
webRequest.ContinueTimeout = 12 * 60 * 60 * 1000;
webRequest.Method = "PUT";
using (Stream stream = webRequest.GetRequestStream())
{
stream.WriteTimeout = 12 * 60 * 60 * 1000;
writeToStream(stream);
stream.Flush();
stream.Close();
}
但是在arround 200mb處我收到IOException(底層連接已關閉。寫入期間發生意外錯誤)
我已經在互聯網上搜索了,發現了一些建議將KeepAlive設置為false,將HttpVersion
和ConnectionLimit
設置為可見。
我嘗試了不同的設置,但始終是相同的。
由於內存消耗,我不能使用HttpClient
。
該代碼適用於小文件。
OneDrive已經支持大文件上傳https://gist.github.com/rgregg/37ba8929768a62131e85
您是否嘗試過將LIVE SDK用於Windows運行時。
http://msdn.microsoft.com/en-us/library/dn659730.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh826531.aspx
希望有了它,您可以實現,因為它提供了asyc上傳。
注意:這是題外話。 但是我仍然想共享。我嘗試使用AWS開發工具包上傳到Amazon S3,它確實可以工作,並且我嘗試使用大約800MB的文件。
當前無法通過REST API上傳大於100MB的文件。 希望這種情況將來會有所改善。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.