title: How to upload (put) image using Volley
body: <p>I need to upload image to certain URL. Classic HTTP request building would look lik this:</p>
  
  <pre><code>            HttpClient httpClient = new DefaultHttpClient();
              HttpContext localContext = new BasicHttpContext();
              HttpPost httpPost = new HttpPost(
                      getString(R.string.WebServiceURL)
                              + "/cfc/iphonewebservice.cfc?method=uploadPhoto");
  
              MultipartEntity entity = new MultipartEntity(
                      HttpMultipartMode.BROWSER_COMPATIBLE);
  
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              bitmap.compress(CompressFormat.JPEG, 100, bos);
              byte[] data = bos.toByteArray();
              entity.addPart("photoId", new StringBody(getIntent()
                      .getStringExtra("photoId")));
              entity.addPart("returnformat", new StringBody("json"));
              entity.addPart("uploaded", new ByteArrayBody(data,
                      "myImage.jpg"));
              entity.addPart("photoCaption", new StringBody(caption.getText()
                      .toString()));
              httpPost.setEntity(entity);
  </code></pre>
  
  <p>In short, suppose that what I need to do is to use <code>httpPost.setEntity()</code> method to put an image into a request.</p>
  
  <p>I already know how to build request using Volley library; one has to override <code>getBody</code> method in <code>com.android.volley.Request</code> class, for example like this:</p>
  
  <pre><code>public byte[] getBody() throws AuthFailureError {
      JsonObject json = new JsonObject();
      Set&lt;String&gt; keySet = mParameters.keySet();
      for (String key : keySet) {
          json.addProperty(key, mParameters.get(key));
      }
  
      return json.toString().getBytes();
  }
  </code></pre>
  
  <p>Now the problem is how to set entity in <code>Request</code> class? there's no method like <code>setEntity()</code>.</p>