Sending A Image To Servlet In Java How To Get The Image In Servlet
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
Solution 1:
Use something like commons fileupload.
There are examples in the Apache docs, and all over the web.
Solution 2:
Servlet 3.0 has support for reading multipart data. MutlipartConfig support in Servlet 3.0 If a servelt is annotated using @MutlipartConfig annotation, the container is responsible for making the Multipart parts available through
- HttpServletRequest.getParts()
- HttpServletRequest.getPart("name");
Solution 3:
use http://commons.apache.org/fileupload/using.html
privateDiskFileItemFactoryfif=newDiskFileItemFactory();
protectedvoiddoPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
booleanisMultipart= ServletFileUpload.isMultipartContent(req);
if(!isMultipart)
thrownewServletException("upload using multipart");
ServletFileUploadupload=newServletFileUpload(fif);
upload.setSizeMax(1024 * 1024 * 10/* 10 mb */);
List<FileItem> items;
try {
items = upload.parseRequest(req);
} catch (FileUploadException e) {
thrownewServletException(e);
}
if(items == null || items.size() == 0)
thrownewServletException("No items uploaded");
FileItemitem= items.get(0);
// do something with file item...
}
Post a Comment for "Sending A Image To Servlet In Java How To Get The Image In Servlet"