Chris
Chris

Reputation: 1642

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.

Upvotes: 0

Views: 1898

Answers (3)

Ivan K.
Ivan K.

Reputation: 48

OneDrive already support large files upload https://gist.github.com/rgregg/37ba8929768a62131e85

Upvotes: 1

Brad
Brad

Reputation: 4202

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.

Upvotes: 0

Arindam Nayak
Arindam Nayak

Reputation: 7462

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.

Upvotes: 0

Related Questions