MIDlet upload photo problem
Hi all, I am developing a MIDlet which allows the user to take a photo add some text and then upload it to a servlet.
My problem is with uploading.
I upload
an Integer
A string
size of photo byte[]array
photo
I can upload the first 3 no problem but not all the bytes for the photo seem to be received by the servlet..
My code for the MIDlet is
String job_No = Integer.toString(upJobNo);
String picString = new String(upLoadImage);
int picSize = upPicture.length;
String size = Integer.toString(picSize);
String allData = job_No+"&"+upPicNotes+"&"+size+"&"+picString;
byte[] dataToSend = allData.getBytes();
String dataLength = Integer.toString(allData.length());
c = (HttpConnection)Connector.open(url2, Connector.READ_WRITE, true);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
c.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("content-type", "multipart/form-data; " );
c.setRequestProperty("Content-Length", dataLength);
c.setRequestProperty("Content-Language", "en-CA");
os = c.openOutputStream();
os.write(allData.getBytes());
os.flush();
and my servlet code is....
int dataLength = request.getContentLength();
BufferedReader br = request.getReader();
String allData = "";
try
{
String data= "";
while((data = br.readLine()) != null)
{
allData = allData + data;
}
}
finally{br.close();}
I then seperate the String into the individual parts again, and there is never the full bytes for the photo..
What am I doing worng??
also the request.getContentLength() returns -1.
Any help will be appreciated.
Thanks in advance.
Re: MIDlet upload photo problem
Hi Kmcgivern,
I am with a similar problem. could you send me its complete code for me to analyze, MIDLet and Servlet?
Thanks. Clésio de Miranda.
e-mail: [email]clesiodemiranda@yahoo.com.br[/email]
Re: MIDlet upload photo problem
Hi Kmcgivern,
I think i can help. I know the way to upload multipart (image...) data to mysql database using php, and how to download that from mysql. after downloding u can append the image to an web site. If u can send me ur codings, i think i can make it work and send u the completed work.
here's my email : [email]rronyyy@yahoo.com[/email]
Re: MIDlet upload photo problem
have a look at this example on Forum Nokia Wiki,
[url]http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_with_J2ME[/url]
As for storing it in the Database you can either store the image itself as a blob or simply store the path to the image as text.