2

I was wondering if someone could help, or am I missing something. In the articles found here http://msdn.microsoft.com/en-us/library/office/dn450841(v=office.15).aspx#bk_FileStartUpload

They refer to using the /getfilebyserverrelativeurl. When I build my request and try and make a HttpWebRequest I get

The length of the URL for this request exceeds the configured maxUrlLength value

in the webresponse.

I'm making these requests from a console application against Office 365/SharePoint Online.

The url length is is 305 in this test case.

This is the code I am using

            HttpWebRequest request = HttpWebRequest.Create(resourceUrl) as HttpWebRequest;
            request.Credentials = _credentials;
            request.CookieContainer = _cookieContainter;
            request.Headers.Add("X-RequestDigest", _formDigest);
            request.Method = "POST";
            request.Timeout = 3600000;
            request.Accept = "application/json; odata=verbose";
            request.ContentLength = incomingStream.Length;
            request.AllowWriteStreamBuffering = false;
            request.KeepAlive = false;

            using (var reqStream = request.GetRequestStream()) {
                incomingStream.CopyTo(reqStream);
            }

            WebResponse response = request.GetResponse();
            using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) {
                result = sr.ReadToEnd();
            }

When its caught by the WebException and I read the exception response all I get is this "The length of the URL for this request exceeds the configured maxUrlLength value."

This is the resourceUrl:

https://tenant-my.sharepoint.com/personal/user_account_tenant_onmicrosoft_com/_api/web/getfilebyserverrelativeurl('/personal/user_account_tenant_onmicrosoft_com/Documents/Test/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso.001')/startupload(uploadId=guid'38acfb37-ccd5-4ac1-961d-090ce1ed9d6f')

3
  • 1
    Is your entire request URL longer than 2000 characters?
    – John-M
    Dec 19 '14 at 15:13
  • Can you provide the code you are using?
    – wjervis
    Dec 19 '14 at 15:20
  • Added more details to question.
    – Webfort
    Dec 20 '14 at 16:39
2

Instead of

getFileByServerRelativeUrl

you can use

GetFileById or GetFolderById

To upload a new file, you can use the below url

/_api/web/GetFolderById('UniqueId')/Files/add(url='filename',overwrite=true)


Reference: http://msdn.microsoft.com/en-us/library/office/dn450841%28v=office.15%29.aspx

1
  • I've tried that. I've used that for other calls. Trying to get the file start upload to work which is the link in the question. Thanks
    – Webfort
    Dec 26 '14 at 11:30
15

In case it helps, we had a similar (but not exact-same) situation. The URL parameters are not included in the length-restriction (at least not this restriction), so we changed our URL to be like so (to edit the original example) :

https://tenant-my.sharepoint.com/personal/user_account_tenant_onmicrosoft_com/_api/web/getfilebyserverrelativeurl(@v)/startupload(uploadId=guid'38acfb37-ccd5-4ac1-961d-090ce1ed9d6f')?@v='/personal/user_account_tenant_onmicrosoft_com/Documents/Test/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso.001'

That appears to be working as expected.

Be aware of the 260 char max path limitation in general, though. If you try and add a file[name] to a folder and that total length exceeds the limit, you have a different problem with a known SP limitation.

Best of luck!

-AJ

5
  • 3
    +1 for this answer - should be the marked answer.
    – thastark
    Apr 11 '16 at 16:39
  • This is brilliant.
    – vinod
    Aug 18 '16 at 22:55
  • Really awesome tricky logic you posted, many thanks to you Feb 1 '17 at 7:00
  • Works with minimal changes to original code, nice!
    – Cardin
    Aug 30 '19 at 1:39
  • you dah man user5346346436 Mar 3 at 3:44
-2

Change the method from "GET" to "POST" and that will resolve the URL length issue.

2
  • In this case it needs to be a post.
    – Webfort
    Dec 20 '14 at 16:40
  • then you have to include the urls in the body of the request not on the url itself. Mar 17 '20 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.