Following Java code is an example for uploading a file attachment to the SharePoint 2013 list item.
String uploadquery =siteurl+ _api/web/Lists/GetByTitle('ListName')/items(1)/AttachmentFiles/add(FileName='File1.txt')";
HttpPost httppost = new HttpPost(uploadquery);
httppost.addHeader("Accept", "application/json;odata=verbose");
httppost.addHeader("X-RequestDigest", FormDigestValue);
httppost.addHeader("X-HTTP-Method", "PUT");
httppost.addHeader("If-Match", "*");
StringEntity se = new StringEntity("This is a Body");
httppost.setEntity(se);
HttpResponse response = httpClient.execute(httppost, localContext);
It creates the file with the content.But it returns the following error in the response.
{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The type SP.File does not support HTTP PATCH method."}}}
what causes this issue?
in Above code,I upload simple text content.But How to upload other file types such as excel/ppt or images to sharepoint list item ?