I am following the MSDN article, "Code example 1: Upload a file across SharePoint domains by using the REST API and jQuery" found
here.
The file actually upload pefectly; however, when it tries to process the 'getListItem' function so that the file can be renamed, I receive an 'Access Denied.' error. I have checked to make sure that the app part has write permissions and that even on the list 'everyone' is given permissions (I know this is not need, but I wanted overkill).
I cannot figure out why it can upload to a folder and then not read from the same location? Any ideas?
Below is the code in question:
// Get the list item that corresponds to the uploaded file.
var getItem = getListItem(file.d.ListItemAllFields.__deferred.uri);
// Get the list item that corresponds to the file by calling the file's ListItemAllFields property.
function getListItem(fileListItemUri) {
// Construct the endpoint.
// The list item URI uses the host web, but the cross-domain call is sent to the
// add-in web and specifies the host web as the context site.
fileListItemUri = fileListItemUri.replace(hostWebUrl, '{0}');
fileListItemUri = fileListItemUri.replace('_api/Web', '_api/sp.appcontextsite(@target)/web');
var listItemAllFieldsEndpoint = String.format(fileListItemUri + "?@target='{1}'", appWebUrl, hostWebUrl);
// Send the request and return the response.
return jQuery.ajax({
url: listItemAllFieldsEndpoint,
type: "GET",
headers: { "accept": "application/json;odata=verbose" }
});
}