Q:

Error trying send an image file with Volley?

I have an image that I'm trying send to my web service with others params using Volley library. The problem is I don't know how can I pass this image about the url using POST.
Looking for a solution I have founded any suggestions to use MultiPart and I'm trying implement that but still can't do this works.
I created other constructor in my Application, this constructor should receive a File but doesn't work also and HashMap doesn't accept File param
How can I do this ?
I'm trying this.
public class ApplicationController extends Request<JSONObject>{
        private Map<String, String> headers;    
        private Map<String, String> params;
        private Response.Listener<JSONObject> listener;
        private File imageFile;
        private MultipartEntityBuilder mBuilder = MultipartEntityBuilder.create();

        public ApplicationController(String url, Map<String, String> params, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
            super(Method.GET, url, errorListener);
            this.listener = listener;
            this.params = params;
        }

        public ApplicationController(int method, String url, Map<String, String> params, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
            super(method, url, errorListener);
            this.listener = listener;
            this.params = params;
        }

        /** construtor to send image */
        public ApplicationController(int method, 
                                     String url, 
                                     Map<String, String> params, 
                                     Response.Listener<JSONObject> listener, 
                                     Response.ErrorListener errorListener,
                                     File file) {
            super(method, url, errorListener);
            this.listener = listener;
            this.params = params;
            this.imageFile = file;
        }

        protected Map<String, String> getParams() throws AuthFailureError {
            return params;
        };

        public Map<String, String> getHeaders() throws AuthFailureError {
            headers = new HashMap<String, String>();
            String cred = String.format("%s:%s", BasicAuthenticationRest.USERNAME, BasicAuthenticationRest.PASSWORD);
            String auth = "Basic " + Base64.encodeToString(cred.getBytes(), Base64.DEFAULT);
            headers.put("Authorization", auth);

            return headers;
        };

        private void buildMultipartEntity(){
            mBuilder.addBinaryBody("", imageFile, ContentType.create("image/png"), imageFile.getName());
            mBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            mBuilder.setLaxMode().setBoundary("xx").setCharset(Charset.forName("UTF-8"));
        }

        @Override
        public String getBodyContentType(){
            String contentTypeHeader = mBuilder.build().getContentType().getValue();
            return contentTypeHeader;
        }

        @Override
        public byte[] getBody() throws AuthFailureError{
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try{
                mBuilder.build().writeTo(bos);
            }catch (IOException e){
                VolleyLog.e("IOException writing to ByteArrayOutputStream bos, building the multipart request.");
            }        
            return bos.toByteArray();
        }

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            try {
                String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
                return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
            } catch (UnsupportedEncodingException e) {
                return Response.error(new ParseError(e));
            } catch (JSONException je) {
                return Response.error(new ParseError(je));
            }
        }

        @Override
        protected void deliverResponse(JSONObject response) {
            listener.onResponse(response);
        }

}

Using 
/** add an user and upload your foto(image) */
public ApplicationController insert(Usuario u, File imageFile, final UsuarioAdapter listener){
    boolean insert = false; 

    HashMap<String, String> params = new HashMap<String, String>();
        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", imageFile);      

    ApplicationController apc = new ApplicationController(Method.POST, urlPost.toString(), params,  
        new Response.Listener<JSONObject>() { 
            @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());
            }                                                                         
        }, File file);

    return apc;
}

A:

Encode the file to a base 64 encoded string and set that in the body (just make sure your server accepts this format!). Google how to do this in java, it's everywhere
params.put("uploadedfile", base64EncodedImageFile);    

