Send jpg images to server (json)
<p>I am trying to write code to send jpg images to a server that can receive JSON requests. This images are stored on the device. I am basically porting a Python code that uses <a href="http://docs.python-requests.org/en/master/" rel="nofollow noreferrer">Requests: HTTP for Humans</a> to communicate with a server. So far I managed to establish the communication with the code I pasted below. So I can see some hope.</p>

<pre><code>     // JAVA code on Android
     String URL = BASE_URL + "/relative_url";

     JsonObjectRequest postRequest = new JsonObjectRequest( Request.Method.POST, URL, null,
            new Response.Listener&lt;JSONObject&gt;() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.i(TAG, "Successful POST request");
                    try {
                        sceneid = response.getInt("id");
                        Log.i(TAG, "Scene id: " + sceneid);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.i(TAG, "Bad POST request");
                }
            }) {
                @Override
                public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
                    Map&lt;String, String&gt; headers = new HashMap&lt;&gt;();
                    String credentials = "myuser:mypass";
                    String auth = "Basic " +  Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
                    headers.put("Authorization", auth);
                    return headers;
                }
    };
    queue.add(postRequest);
</code></pre>

<p>However, I am not able to replicate the Python code below. I already checked thoroughly for a solution online, but I did not manage to make it work. The solutions I found either use deprecated libraries or the code does not work. The command in python I am trying to replicate is:</p>

<pre><code># Python code to replicate in JAVA
auth = {'myuser', 'mypass'}
file = {'jpgdata': open('myimg.jpg','rb')}
req = requests.post(BASE_URL + '/relative_url', params={'param', param}, files=file, auth=auth)
</code></pre>

<p>Some help will be really appreciated.</p>

<p>Thank you in advance.</p>