简体   繁体   中英

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.

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)

I've searched the internet and found some recommendation to set KeepAlive to false, set the HttpVersion and the ConnectionLimit , as you can see.

I've tried it with different settings, but it is always the same.

I can not use HttpClient , because of Memory consumption.

The code works with small files.

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

Have you tried with LIVE SDK for windows runtime.

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.

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.

It is currently not possible to upload a file larger than 100MB via the REST API. Hopefully that's a situation that's improved in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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