public byte[] getArrayFromZip( String zipPath) {
File myFile = new File(zipPath);
ByteArrayOutputStream byteBuffer = null;
try (InputStream inputStream = new FileInputStream(myFile)) {
byteBuffer = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
}catch (IOException e){
Log.e("Free Entwickler", "IOException: " + e);
}
return byteBuffer.toByteArray();
}
private void uploadZip() {
VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST, ROOT_URL,
new Response.Listener<NetworkResponse>() {
@Override
public void onResponse(NetworkResponse response) {
try {
JSONObject obj = new JSONObject(new String(response.data));
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
Log.e("GotError",""+error.getMessage());
}
}) {
@Override
protected Map<String, DataPart> getByteData() {
Map<String, DataPart> params = new HashMap<>();
long imagename = System.currentTimeMillis();
byte[] zipArray = getArrayFromZip(Environment.getExternalStorageDirectory() + "/Download/" + "Ezip" + ".zip");
params.put("zip", new DataPart(imagename + ".zip", zipArray ));
return params;
}
};
//adding the request to volley
Volley.newRequestQueue(this).add(volleyMultipartRequest);
}