0
にパラメータを指定して画像を送信するこれは私がパラメータで私の画像を添付して使用していたコードです:httpurl
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();
}
と私はその後、値を画像を送信しない場合、私はthis
を参照していますサーバーに完全に送信されます。イメージを追加すると、テキストパラメータが送信できなくなってしまいます。
MultipartEntityは非推奨です。使用していません。 –
ドキュメントから、MultipartEntityBuilderを代わりに使用する必要があることがわかります。参照のため –
。 http://stackoverflow.com/questions/19196292/the-type-multipartentity-is-deprecated?answertab=active#tab-top –