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?