I am working with an application where i am trying to uploading a file to server with android volley plus SimpleMultiPartRequest, my file gets successfully uploaded to server and I receive file url but with extension xyz.octet-stream, no matter whatever the file is. Below is the code for SimpleMultiPartRequest.
SimpleMultiPartRequest request = new SimpleMultiPartRequest(methodType, url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
uploadSettable.set(s);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
uploadSettable.setException(volleyError);
Log.v(TAG,volleyError.toString());
}
}){
@Override
public Map<String, String> getFilesToUpload() {
Map<String,String> map = new HashMap<>();
map.put("FileData",filePath);
return map;
}
@Override
public int getMethod() {
return Method.POST;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
final Map<String, String> map = new HashMap<>();
map.put(PrefUtils.AUTHORIZATION_KEY, "Bearer " + PrefUtils.getString(PrefUtils.PREF_UTILS_ACCESS_TOKEN,"N/A",ArkaaApplicationClass.getInstance().getBaseContext()));
return map;
}
@Override
public void onProgress(final long transferredBytes, final long totalSize) {
fileSize = totalSize;
super.onProgress(transferredBytes, totalSize);
new Thread(new Runnable() {
@Override
public void run() {
if(progressBarStatus < totalSize) {
// performing operation
progressBarStatus = (int)((transferredBytes*100)/totalSize);
try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
// Updating the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
// performing operation if file is downloaded,
if (progressBarStatus >= totalSize) {
// sleeping for 1 second after operation completed
try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
// close the progress bar dialog
progressBar.dismiss();
}
}
}).start();
}
};
request.setShouldCache(false);
request.setRetryPolicy(new DefaultRetryPolicy(10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
ArkaaApplicationClass.getInstance().addToRequestQueue(request);