![](/img/trans.png)
[英]How to pass byte array of an Image over a soap web-service(XML) and decode this byte array on android device to convert it back to an Image
[英]how to upload image as byte array to Rest web-service using http post method in android
我創建了可以將圖像上傳到網絡服務的應用程序。 這樣,在使用HTTP post方法上傳圖像以休息Web服務時,如何上傳圖像作為byte []數組。 如何將byte []數組以及文件名和文件長度傳遞給Web服務?
Drawable d = context.getResources().getDrawable(R.drawable.human_head);
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
byte[] bitmapdata = stream.toByteArray();
entity.addPart("image", new ByteArrayBody(bitmapdata,".png"));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, WebService.getInstance(Constants.WEB_SERVER).getLocalContext());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.