jeudi 22 janvier 2015

"413 Request Entity Too Large" when trying to Upload Multipart Entity using Android volley


Vote count:

0




I am using android Volley, and I have a multipartEntity request Class for uploading images. This class works fine usually, but When I try to upload an image that was freshly taken by the camera, which is about a few megs, I get the error "413 Request Entity Too Large" from the server. I've verified with my server guy and he does not impose a size limit. My guess is that somehow I need to manually set my content size in my multipart entitiy, but not sure where to do this, Here is my code:



public class MultipartRequest extends Request<JSONObject> {
private final JSONObject jsonPart;

MultipartEntityBuilder entity = MultipartEntityBuilder.create();
HttpEntity httpentity;
private static final String FILE_PART_NAME = "file";

private final Response.Listener<JSONObject> mListener;
private final File mFilePart;
//private final Map<String, String> mStringPart;

public MultipartRequest(String url, Response.ErrorListener errorListener,
Response.Listener<JSONObject> listener, File file
, JSONObject jsonPart
/*, Map<String, String> mStringPart*/) {
super(Method.POST, url, errorListener);

mListener = listener;
mFilePart = file;
this.jsonPart = jsonPart;
entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
buildMultipartEntity();
}

private void buildMultipartEntity() {

if (jsonPart != null) {
entity.addTextBody("loopMessage", jsonPart.toString(), ContentType.TEXT_PLAIN);
}
//entity.addPart(FILE_PART_NAME, new FileBody(mFilePart));
entity.addBinaryBody(FILE_PART_NAME, mFilePart);
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
params.put("Authorization", StaticWebClient.token);
params.put("x-client-id", StaticWebClient.clientId);
return params;
}

@Override
public String getBodyContentType() {
return httpentity.getContentType().getValue();
}

@Override
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
httpentity = entity.build();
httpentity.writeTo(bos);
} catch (IOException e) {
e.printStackTrace();
VolleyLog.e("IOException writing to ByteArrayOutputStream");
}
return bos.toByteArray();
}
}


asked 1 min ago







"413 Request Entity Too Large" when trying to Upload Multipart Entity using Android volley

Aucun commentaire:

Enregistrer un commentaire