title: how to upload file in java for given SAS URI
body: <p>Sample C# code:</p>
  
  <pre><code> static void UploadFile(string sasUrl, string filepath)
      {
          using (var client = new HttpClient())
          {
              client.DefaultRequestHeaders.Add("x-ms-version", Version);
              client.DefaultRequestHeaders.Add("x-ms-client-request-id", SessionGuid);
  
              StringBuilder sb = new StringBuilder("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;BlockList&gt;");
  
              foreach (byte[] chunk in GetFileChunks(filepath))
              {
                  var blockid = GetHash(chunk);
                  HttpRequestMessage chunkMessage = new HttpRequestMessage()
                  {
                      Method = HttpMethod.Put,
                      RequestUri = new Uri(sasUrl + "&amp;timeout=90&amp;comp=block&amp;blockid=" + WebUtility.UrlEncode(blockid)),
                      Content = new ByteArrayContent(chunk)
                  };
                  chunkMessage.Headers.Add("x-ms-blob-type", "BlockBlob");
                  chunkMessage.Content.Headers.Add("MD5-Content", blockid);
  
                  TimeAction("Uploading chunk " + blockid + " took {0} ms", () =&gt;
                  {
                      var response = client.SendAsync(chunkMessage).Result;
                  });
                  sb.Append("&lt;Latest&gt;");
                  sb.Append(blockid);
                  sb.Append("&lt;/Latest&gt;");
              }
              sb.Append("&lt;/BlockList&gt;");
  
              Trace.WriteLine(sb.ToString());
  
              HttpRequestMessage commitMessage = new HttpRequestMessage()
              {
                  Method = HttpMethod.Put,
                  RequestUri = new Uri(sasUrl + "&amp;timeout=90&amp;comp=blocklist"),
                  Content = new StringContent(sb.ToString())
              };
              TimeAction("Commiting the blocks took {0} ms", () =&gt;
              {
                  var commit = client.SendAsync(commitMessage).Result;
              });
          }
      }
  </code></pre>
  
  <p>I am stuck at the point where I've to upload a file. Also want to know what the reason is to commit in given code?</p>
  
  <p>my progress so far is :</p>
  
  <pre><code>public static void uploadFile(String sasUrl , String filepath , String sessionGuid)
  {
      File file = new File(filepath);
      FileInputStream fileInputStream=null;
      Response reply = new Response();
      HttpClient client = HttpClientBuilder.create().build();
      HttpPost request = new HttpPost(sasUrl);
      request.setHeader("x-ms-version", "2013-08-15");
      request.setHeader("x-ms-client-request-id", sessionGuid);
      StringBuilder sb = new StringBuilder("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;BlockList&gt;");
  
  
  }
  }
  </code></pre>
  
  <p>Note: I cannot run the code multiple times as I cannot spam the server. Any suggestions will be appreciated
  Referring to : <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/dn800660(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/hardware/dn800660(v=vs.85).aspx</a></p>