While I am uplodaing multiple images in j2me to servlet, I am able to get first image in servlet but not able get second image. is something wrong in my code? could you please suggest
This is my code.
// For First Image uploading
String message1 = ""; message1 += "-----------------------------4664151417711" + CrLf; message1 += "Content-Disposition: form-data; name=\"image1\"; filename=\"" + FILE1 + "\"" + CrLf; message1 += "Content-Type: image/jpeg" + CrLf; message1 += CrLf;
// the image is sent between the messages ni the multipart message.
String message2 = "";
message2 += CrLf + "-----------------------------4664151417711--" + CrLf;
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
// might not need to specify the content-length when sending chunked data.
// conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length)));
System.out.println("open os");
os = conn.openOutputStream();
System.out.println(message1);
os.write(message1.getBytes());
// SEND THE IMAGE
int index = 0;
int size = 1024;
do{
System.out.println("write:" + index);
if((index+size)>imgData1.length){
size = imgData1.length - index;
}
os.write(imgData1, index, size);
index+=size;
progress(imgData1.length, index); // update the progress bar.
}while(index<imgData1.length);
// For Second Image uploading
message1 = ""; message1 += "-----------------------------4664151417711" + CrLf; message1 += "Content-Disposition: form-data; name=\"image2\"; filename=\"" + FILE2 + "\"" + CrLf; message1 += "Content-Type: image/jpeg" + CrLf; message1 += CrLf;
// the image is sent between the messages ni the multipart message.
message2 = "";
message2 += CrLf + "-----------------------------4664151417711--" + CrLf;
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
// might not need to specify the content-length when sending chunked data.
// conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length)));
System.out.println(message1);
os.write(message1.getBytes());
// SEND THE IMAGE
int index = 0;
int size = 1024;
do{
System.out.println("write:" + index);
if((index+size)>imgData2.length){
size = imgData2.length - index;
}
os.write(imgData2, index, size);
index+=size;
progress(imgData2.length, index); // update the progress bar.
}while(index<imgData2.length);