I tried to upload large files (over 3M) to SharePoint 2013 Online in a provider-hosted APP (OAuth authentication by passing “StandardTokens”). I tried many ways, but there is no way to work for so far.
1. Use SharePoint Client Model below, but in SharePoint online, the limitation of file size is about 3M. Other people have the similar issue (http://community.office365.com/en-us/forums/154/p/15446/71238.aspx#71238)
microsoft.sharepoint.client.file uploadedfile = folder.files.add(filecreationinformation);
clientcontext.load(uploadedfile);
clientcontext.executequery();
2. Tried to increase MaxReceivedMessageSize according tohttp://msdn.microsoft.com/en-us/library/ff599489.aspx, but I cannot call Server Object Model to do it with SharePoint Online. Tried to find if I can change the settings through PowerShell to SharePoint Online, but there is no command exposed for MaxReceivedMessageSize in Windows PowerShell for SharePoint Online cmdlets (http://technet.microsoft.com/en-us/library/fp161364.aspx).
3. I tried a workaround to use WebDAV in http://stackoverflow.com/questions/15077305/uploading-large-files-to-sharepoint-365. It works when I use claims based authentication by providing user name and password. However, in provider-hosted APP, I cannot use this kind of authentication, and need OAuth authentication work. I added "Authorization","Bearer "+ accessToken in HTTTP headers according tohttp://code.msdn.microsoft.com/officeapps/SharePoint-2013-Use-HTTPs-dc7227a7. It works well for Web Service calls, but it doesn’t work for WebDAV calls. Here is the code.
System.Net.ServicePointManager.Expect100Continue =false;
HttpWebRequest request = HttpWebRequest.Create(UrlCombine(sharepointFileInfo.SharepointhHostUrl, uploadUrl))asHttpWebRequest;
request.Method = "PUT";
request.Accept = "*/*";
request.ContentType = "multipart/form-data; charset=utf-8";
//request.CookieContainer = GetCookieContainer(); //it works with SAML cookies
request.Headers.Add("Authorization", "Bearer " + accessToken);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
request.Headers.Add("Accept-Language","en-us");
request.Headers.Add("Translate","F");
request.Headers.Add("Cache-Control","no-cache");
request.ContentLength = bi.Data.Length;
using (Stream req = request.GetRequestStream())
{
req.Write(bi.Data, 0, bi.Data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = newStreamReader(response.GetResponseStream());
string respondBody = reader.ReadToEnd();
This is what I got after “PUT”
"<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href=\"https://objectivadev.sharepoint.com/sites/DEV2/_layouts/15/Authenticate.aspx?Source=%2Fsites%2FDEV2%2FShared%20Documents%2FPresentation1%2Epptx\">here</a>.</h2>\r\n</body></html>\r\n"
4. I tried Microsoft.SharePoint.Client.File.SaveBinaryDirect() in Client Model. There are many posts that indicate SaveBinaryDirect() doesn’t work due to cookies being attached to request too late (http://stackoverflow.com/questions/15077305/uploading-large-files-to-sharepoint-365). I got http 403 error on SaveBinaryDirect().
"917656; Access denied. Before opening files in this location, you must first browse to the web site and select the option to login automatically."
Basically, I tried the four ways above, but all failed. It is such a common scenario to upload a little bit large file (3M) to SharePoint 2013 Online in an APP, but there is no solution for me yet. Would you please help me find a way out?