VolleyPlus
VolleyPlus copied to clipboard
SimpleMultipartRequest always returns octet-stream file extension
I am working with an android application where I am trying to upload a file to server with SimpleMultipartRequest, either I upload the jpeg,pdf,png but i always receive xyz.octet-stream file path in response. Even if I add some extra parameter. Below is the code for the same.
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);
}
}) {
@Override
public Map<String, String> getFilesToUpload() {
Map<String, String> map = new HashMap<>();
map.put("FileData", filePath);
return map;
}
@Override
public Map<String, MultiPartParam> getMultipartParams() {
HashMap<String, MultiPartParam> stringMultiPartParamHashMap = new HashMap<>();
stringMultiPartParamHashMap.put("Content-Type",new MultiPartParam("Content-Type","image/jpeg"));
return super.getMultipartParams();
}
@Override
public int getMethod() {
return Method.POST;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map headerMap = new HashMap();
headerMap.put(ServiceConfig.AUTHORIZATION_KEY, ServiceConfig.BEARER_KEY + SharedPrefUtil.getAccessToken(
ServiceConfig.ACCESS_TOKEN_KEY, KeyConstants.SHARED_PREF_DEFAULT_VALUE, DoctorApplicationClass.getInstance().getBaseContext()));
return headerMap;
}
@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) {
progressBarStatus = (int) ((transferredBytes * 100) / totalSize);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
if (progressBarStatus >= totalSize) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();
}
};
No Response till now for the above issue.
This is the bug in SimpleMultiPartRequest where response always return with .octet.stream.
Facing similar issue. Trying to upload a Jpeg Image but it's content type is set to application/octet-stream which server blocks from uploading. It should be an image/jpeg type instead
smr.addFile("filePic", getPath(imageUri));
yes, i have the same problem, its octet-stream always
I solved this problem by changing the content-type in lib itself.
Thanks & Regards Vikas Grover +917503298590
On Sat, Mar 31, 2018 at 1:05 PM, scsonic [email protected] wrote:
yes, i have the same problem, its octet-stream always
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DWorkS/VolleyPlus/issues/40#issuecomment-377673737, or mute the thread https://github.com/notifications/unsubscribe-auth/APLxnusR7PcpWZr9pk0gQZOT2mLCf5HIks5tjzHfgaJpZM4G0FhT .
@vikasgrover33 How do you do that?