This is the code i am using to attach my image with parameters :
DataOutputStream request = new DataOutputStream(
con.getOutputStream());
if(bitmap!=null)
{
request.writeBytes(twoHyphens + boundary + crlf);
request.writeBytes("Content-Disposition: form-data; name=\"profile_picture\";filename=\"profile_picture.jpg\"" + crlf);
request.writeBytes("Content-Type: image/jpeg" + crlf);
request.writeBytes(crlf);
byte[] pixels = new byte[bitmap.getWidth() * bitmap.getHeight()];
for (int i = 0; i < bitmap.getWidth(); ++i) {
for (int j = 0; j < bitmap.getHeight(); ++j) {
//we're interested only in the MSB of the first byte,
//since the other 3 bytes are identical for B&W images
pixels[i + j] = (byte) ((bitmap.getPixel(i, j) & 0x80) >> 7);
}
}
request.write(pixels);//your image array here buddy
request.writeBytes(crlf);
request.writeBytes(twoHyphens + boundary + crlf);
request.writeBytes(twoHyphens + boundary + crlf);
Set<Map.Entry<String, Object>> set=params.valueSet();
Iterator itr = set.iterator();
while (itr.hasNext()) {
Map.Entry me = (Map.Entry)itr.next();
request.writeBytes("Content-Disposition: form-data; name=\""+me.getKey().toString()+"\"" + crlf);
request.writeBytes(crlf);
request.writeBytes(me.getValue().toString());//your parameter value
request.writeBytes(crlf);
request.writeBytes(twoHyphens + boundary +
crlf);
}
request.flush();
request.close();
}
and i am referring to this
if i don't send image then the values are sent to the server perfectly, if i add image then i get that the text parameters are not been able to sent.