I have a highly customized Edit form for a list. To make life easier for users, and to manage the size of the list better, instead of attaching files directly to the list, we set up a documents library and then embedded a view of the library on the form. Documents being uploaded would go to a folder whose name matched the ID value of the list item. When we built the form in SP 2010, everything was working just fine.

Well, for a host of reasons, post-migration, this doesn't work. I'm trying to re-engineer the solution now by putting a custom upload on the form. I'm trying to upload a file via REST, but I keep getting

{"error":{"code":-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression\"web/GetFolderByServerRelativeUrl('/sites/a/b/c/Requests Documents')/files/add(url=filename.docx,overwrite=true)\" is not valid."}}}

I know the URL is valid because when I put the URL (minus the /add...) directly into my browser, it returns results. The complete code block I'm using is

    var url= String.format(
    "/sites/a/b/c/_api/web/GetFolderByServerRelativeUrl('/sites/a/b/c/Requests%20Documents/"+localStorage.folder+"')/files/add(url={1}, overwrite=true)",_spPageContextInfo.webAbsoluteUrl, fileName);

    return jQuery.ajax({
        url: url,
        type: "POST",
        data: arrayBuffer,
        processData: false,
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
            "content-length": arrayBuffer.byteLength

So what's going wrong here?

1 Answer 1


Edit: On second thought, first thing to try might be wrapping the URL with single quotes: url='{1}'.

Original answer:

Try removing the space from inside the add function. From my experience, the comma-space sequence within functions usually causes problems in REST calls.


add(url={1}, overwrite=true)

change this to...


  • 1
    Thank you, that worked! I did both your suggestions, to be on the safe side. But now it's working. Feb 12, 2019 at 16:51
  • @ScottDavis Hi, I have same problem but I had both your suggestions already correct... my url: crm317842.sharepoint.com/sites/crmattachments/_api/web/… I have same response as OP
    – michalh
    Feb 15, 2019 at 7:58
  • @ScottDavis just found it... it was uppercase T in the overwrite value :( oh my .. really?
    – michalh
    Feb 15, 2019 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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