I am using Spring Boot for storing files (of basically as many format as possible - but think along the lines of images, documents) in SharePoint for my application, which is deployed in SAP's Cloud Foundry. I have pretty much followed the steps mentioned in this post's answer (and copied all four files from there) and I got a github repo which pretty much implements the same thing. I've followed them but something is not working for me. (Please refer to the StackOverflow link for further reference of what I'm talking about)
The order of method calls in SharePointServiceCached.java is
parseExecutionDateTime() -> receiveSecurityToken() -> getSignInCookies(securityToken) -> getFormDigestValue(cookies)
I receive the security token (as I checked from my logs) but this is the error message I'm getting:
Document upload failed!org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [403 FORBIDDEN]
Things I have tried for this:
https://protected1.sharepoint.com/sites/protected2
to https://protected1.sharepoint.com/
which again, somehow made it worse. (Obviously, protected1 and protected2 are changed names) @Bean
public RestTemplate restTemplate(RestTemplateBuilder builder)
{
CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier())
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate rest = new RestTemplate(requestFactory);
builder.configure(rest);
return builder.build();
}
Also, previously I was using a CMS for the same thing which returned a document ID associated with the uploaded file. I have enabled the option for document IDs in SharePoint and want to use it similarly, i.e. upload a file -> get a document ID and store it -> use that document ID to fetch the file when required. How can I do this?
Thank you in advance.
Got it. I just had to send the path where I want to store my files.
https://protected1.sharepoint.com/sites/protected2/_api/web/GetFolderByServerRelativeUrl(%27Shared%20Documents/Another%20Folder%27)/files/add(url=%27" + documentID + "%27,overwrite=false)
I am now generating the documentID randomly.