繁体   English   中英

通过C#使用REST api将大文件放入一个驱动器

[英]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,将HttpVersionConnectionLimit设置为可见。

我尝试了不同的设置,但始终是相同的。

由于内存消耗,我不能使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM