title: How to do upload image with Volley library?
body: <p>I have an image and I want to upload this image to my web service using Volley library, the problem is I'm looking for a how to do it but still haven't found.</p>
  
  <p>I found this, but doesn't work to me: <a href="http://develop-for-android.blogspot.com.br/2014/01/using-volley-in-your-application.html" rel="nofollow">http://develop-for-android.blogspot.com.br/2014/01/using-volley-in-your-application.html</a></p>
  
  <p>How can I do this ?</p>
  
  <p>I'm trying this.</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
          Uri selectedImage = data.getData();
          String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
          Cursor cursor = getContentResolver().query(selectedImage,
                  filePathColumn, null, null, null);
          cursor.moveToFirst();
  
          int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
          fotoPerfil = cursor.getString(columnIndex);
          cursor.close();
  
          ImageView imageView = (ImageView) findViewById(R.id.imgView);
          imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  
      }     
  }
  
  UploadoImageToServer upload = new UploadoImageToServer();   
  ApplicationController app = new UsuarioDAO().insert(usuario, upload.upload(fotoPerfil, em[0]), new UsuarioAdapter(){
      @Override
      public void usuarioIsAdded(Boolean result){
          Log.i("Adicionou: ", result + "");
          progress.dismiss();
      }                   
  });
  CustomVolleySingleton.getInstance(getApplicationContext()).addToRequestQueue(app);
  
  public class UploadoImageToServer {
      public String upload(String image,String nomeImagem){
          Bitmap bitmap = BitmapFactory.decodeFile(image);
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); 
          byte [] byte_arr = stream.toByteArray();
          String image_str = Base64.encodeBytes(byte_arr);
          return image_str;               
      }
  }
  
  /** add an user and upload your foto(image) */
  public ApplicationController insert(Usuario u, String uploadFile, final UsuarioAdapter listener) {
      boolean insert = false; 
  
      HashMap&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
      params.put("nome", u.getNome());
      params.put("email", u.getEmail());
      params.put("senha", u.getSenha());      
      params.put("tipo", "usuarios");
      params.put("acao", "add");
      params.put("device_tipo", "android");
      params.put("device", AndroidReturnId.getAndroidId());
      params.put("uploadedfile", uploadFile);
      Log.i("URL: ", urlPost.toString());
  
      ApplicationController apc = new ApplicationController(Method.POST, urlPost.toString(), params,
          new Response.Listener&lt;JSONObject&gt;() {
              @Override
              public void onResponse(JSONObject obj) {
                  try {
                      if(obj.getString("cod").equals("999")){                                                                             
                          listener.usuarioIsAdded(true);
                      }else{
                          listener.usuarioIsAdded(false);                                                     
                      }
                  } catch (JSONException e) {                                                                     
                      e.printStackTrace();
                  }
              }
          }, 
          new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError arg0) {
                  Log.e("ERROR METHOD:", "insert in UsuarioDAO: " + arg0.getLocalizedMessage());
              }                                                                         
          });
  
      return apc;
  }
  </code></pre>