Search code examples
javasharepointfile-uploadsharepoint-2010sharepoint-2013

Not able to upload a document on sharepoint folder using java


I Want to upload the document into Sharepoint Folder.

Below are my observation and Progress

  • I have tried to pick a document from Local Machine and Upload the same into Local Machine (Some Another Folder) This is working fine
  • Now all I wanted to to change is instead of uploading it to some local folder I want to upload it into sharepoint folder

Below Is the Code That I have Tried.

File baseDir = new File(ApplicationProperties.getInstance().getAttachmentUploadBaseDirPath());
if (!baseDir.exists()) {
    baseDir.mkdir();
}

File complaintDir = new File("https://apps.companyname.com/sites/Shared Documents/Test" + "\\" + complaintNumber);
if (!complaintDir.exists()) {
    complaintDir.mkdir();
}

file = new File(complaintDir + "\\"+ filename);
fos = new FileOutputStream(file);

Solution

  • I did some digging and finally got my answer. Steps which I followed:

    1. I tried to create rest api in postman. But I was getting forbidden
      403 as status code.
    2. I tried following blog as I came to know I
      have to generate client id and client secret on sharepoint site. So Here is the blog which is followed :
      http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

    Happy Coding! Thanks.