简体   繁体   English

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

[英]Put large file to one drive with REST api via c#

I want to put a large file (1.4 gb) via rest api to onedrive. 我想通过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();
}

But at arround 200mb I receive an IOException (The underlying connection was closed. Unexpected error during write) 但是在arround 200mb处我收到IOException(底层连接已关闭。写入期间发生意外错误)

I've searched the internet and found some recommendation to set KeepAlive to false, set the HttpVersion and the ConnectionLimit , as you can see. 我已经在互联网上搜索了,发现了一些建议将KeepAlive设置为false,将HttpVersionConnectionLimit设置为可见。

I've tried it with different settings, but it is always the same. 我尝试了不同的设置,但始终是相同的。

I can not use HttpClient , because of Memory consumption. 由于内存消耗,我不能使用HttpClient

The code works with small files. 该代码适用于小文件。

OneDrive已经支持大文件上传https://gist.github.com/rgregg/37ba8929768a62131e85

Have you tried with LIVE SDK for windows runtime. 您是否尝试过将LIVE SDK用于Windows运行时。

http://msdn.microsoft.com/en-us/library/dn659730.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh826531.aspx http://msdn.microsoft.com/en-us/library/dn659730.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh826531.aspx

Hope with this, you can achieve , as it provides asyc upload. 希望有了它,您可以实现,因为它提供了asyc上传。

Note: This is off-topic. 注意:这是题外话。 But still i thought of sharing.I have tried uploading to Amazon S3 using AWS SDK, it does work, and i have tried with around 800MB file. 但是我仍然想共享。我尝试使用AWS开发工具包上传到Amazon S3,它确实可以工作,并且我尝试使用大约800MB的文件。

It is currently not possible to upload a file larger than 100MB via the REST API. 当前无法通过REST API上传大于100MB的文件。 Hopefully that's a situation that's improved in the future. 希望这种情况将来会有所改善。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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