SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see that the OM API can do it, but is there any way to use the REST API to upload files (word docs and PDF's) to a document library, and update the data items as well. I want to use Java to do this, so the OM is not applicable.

share|improve this question

You just use an HTTP PUT to place a file in a library. It's not so much REST as good old HTTP ...

From that link:

WebResponse response = null;

    // Create a PUT Web request to upload the file.
    WebRequest request = WebRequest.Create(SharePointPath);

    request.Credentials = CredentialCache.DefaultCredentials;
    request.Method = "PUT";

    // Allocate a 1 KB buffer to transfer the file contents.
    // You can adjust the buffer size as needed, depending on
    // the number and size of files being uploaded.
    byte[] buffer = new byte[1024];

    // Write the contents of the local file to the
    // request stream.
    using (Stream stream = request.GetRequestStream())
    using (FileStream fsWorkbook = File.Open(UploadedFilePath,
        FileMode.Open, FileAccess.Read))
        int i = fsWorkbook.Read(buffer, 0, buffer.Length);

        while (i > 0)
            stream.Write(buffer, 0, i);
            i = fsWorkbook.Read(buffer, 0, buffer.Length);

    // Make the PUT request.
    response = request.GetResponse();
catch (Exception ex)
    throw ex;

To update them, then make REST calls subsequently. I've not found a way of doing this that isn't two stage.

share|improve this answer
Thanks!:) this works fine for me , and my file is getting uploade to a sharepoint document library.But the file stores in a check out mode, can u let me know how to check in those .... – user10798 Sep 19 '12 at 6:58
My problem is this works, but for instance Excel files are detected as ZIP files by Sharepoint. :(… – Prof. Falken Sep 30 '15 at 11:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.