HttpMultipartRequest: simple file uploads with J2ME
Today’s code is related to file uploads using J2ME. We’ll use Http POST MultiPart requests to handle and transfer data from J2ME application to server; since there is no builtin support for MultiPart, we’ll have to build the request body by hand.
Code is limited to 1 class only (HttpMultipartRequest), that will be easy to include and easy in your code, just instatiate it with its constructor:
HttpMultipartRequest(String url, Hashtable params, String fileField, String fileName, String fileType, byte[] fileBytes) |
and then send data to server (and get response) with its send() method. As you can see from the constructor, this implementation support also parameter passing, that will be posted to server together with the file bytes.
Detailed and explained code (with sample client and server code) is available here: HTTP Post multipart file upload with J2ME Wiki article. To directly download source code, click here.
Girish 10:07 am on February 11, 2009 Permalink
Hi! I have tried using the class in a MIDlet, but I cannot make it work. Can you help me? I’ve posted that on a forum, but I haven’t found any help yet.
http://discussion.forum.nokia.com/forum/showthread.php?p=541133
Kapil Katiyar 9:45 am on September 15, 2011 Permalink
Thanks
sabri 9:29 pm on November 30, 2012 Permalink
hi …
thanx for ur help … the code working success full except the picture cann’t shown after saved on server because viewer can’t open this picture because the fi;e appears to be damaged …
and the size on server is larger than the size on mobile …
please help me to solve this problem ….
thanx