且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送图像用Java servlet中如何获得servlet的图像

更新时间:2023-12-04 14:54:08

使用类似通用FileUpload

有在Apache文档的例子,所有网站。

I am sending a image from android phone to server which is a servlet I am using the HttpClient and HttpPost for this and ByteArrayBody for storing the image before sending.

how do i extract the image from the post request in Servlet.

Here is my code for sending the post request

String postURL = //server url;

HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(postURL);

ByteArrayBody bab = new ByteArrayBody(imageBytes,"file_name_ignored");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("source", bab);
postRequest.setEntity(reqEntity);

HttpResponse response = httpClient.execute(postRequest);

Use something like commons fileupload.

There are examples in the Apache docs, and all over the web.