velosumdev
asked on
J2ME: Upload image (jpg/png) to the server via HTTP connection
Hi,
Phone: Motorola i870
Application allows the user to capture an image. Then it sends two different files to the server using HTTP post. The first one goes through without any problem but the one with the image file does not go through. I want to send that image file as an attachment. Here is my source. It is very urgent. Really appreciate if you be a help in any way.
///Image file --- which does not work.
// Establish file names
String sName = m_midlet.getPgcFile().getN ame();
if (sName.toLowerCase().endsW ith(".pgc" )) {
sName = sName.substring(0, sName.length() - 4);
}
Date date = new Date(System.currentTimeMil lis());
String sDateString = DateUtils.getPaddedDateStr ing(date, '-');
String sTimeString = DateUtils.getPaddedTimeStr ing(date, '-');
String sBaseFileName = sFilePrefix + "_" + sCustId + "_" + m_midlet.getPhoneNumber() +
"_" + sDateString + "_" + sTimeString;
String sPgcFileName = sBaseFileName + ".pgc";
String sJpgFileName = sBaseFileName + ".jpg";
dos.write(FileSender.PREFI X_BYTES);
dos.write(sBoundary.getByt es());
dos.write(FileSender.NEW_L INE_BYTES) ;
//sContentDisposition = "Content-Disposition: form-data; name=\"" +
// sName + "_jpg\"; filename=\"" + sJpgFileName + "\"";
sContentDisposition = "Content-Disposition: form-data; name=\"" +
sName + "_jpg\"; filename=\"" + sJpgFileName + "\"";
dos.write(sContentDisposit ion.getByt es());
dos.write(FileSender.NEW_L INE_BYTES) ;
dos.write(sType.getBytes() );
dos.write(FileSender.NEW_L INE_BYTES) ;
dos.write(FileSender.NEW_L INE_BYTES) ;
dos.write(m_midlet.getPgcF ile().getA ttachedIma ge()); //This is the array of byes of captured image.
dos.write(FileSender.NEW_L INE_BYTES) ;
////////////////PGC file ---- the one which works..
dos.write(FileSender.PREFI X_BYTES);
dos.write(sBoundary.getByt es());
dos.write(FileSender.NEW_L INE_BYTES) ;
String sContentDisposition = "Content-Disposition: form-data; name=\"" +
sName + "_pgc\"; filename=\"" + sPgcFileName + "\"";
dos.write(sContentDisposit ion.getByt es());
dos.write(FileSender.NEW_L INE_BYTES) ;
String sType = "Content-Type: application/octet-stream";
dos.write(sType.getBytes() );
dos.write(FileSender.NEW_L INE_BYTES) ;
dos.write(FileSender.NEW_L INE_BYTES) ;
dos.write(m_midlet.getPgcF ile().getD ata());
dos.write(FileSender.NEW_L INE_BYTES) ;
Thanks in advance.
Praj
Phone: Motorola i870
Application allows the user to capture an image. Then it sends two different files to the server using HTTP post. The first one goes through without any problem but the one with the image file does not go through. I want to send that image file as an attachment. Here is my source. It is very urgent. Really appreciate if you be a help in any way.
///Image file --- which does not work.
// Establish file names
String sName = m_midlet.getPgcFile().getN
if (sName.toLowerCase().endsW
sName = sName.substring(0, sName.length() - 4);
}
Date date = new Date(System.currentTimeMil
String sDateString = DateUtils.getPaddedDateStr
String sTimeString = DateUtils.getPaddedTimeStr
String sBaseFileName = sFilePrefix + "_" + sCustId + "_" + m_midlet.getPhoneNumber() +
"_" + sDateString + "_" + sTimeString;
String sPgcFileName = sBaseFileName + ".pgc";
String sJpgFileName = sBaseFileName + ".jpg";
dos.write(FileSender.PREFI
dos.write(sBoundary.getByt
dos.write(FileSender.NEW_L
//sContentDisposition = "Content-Disposition: form-data; name=\"" +
// sName + "_jpg\"; filename=\"" + sJpgFileName + "\"";
sContentDisposition = "Content-Disposition: form-data; name=\"" +
sName + "_jpg\"; filename=\"" + sJpgFileName + "\"";
dos.write(sContentDisposit
dos.write(FileSender.NEW_L
dos.write(sType.getBytes()
dos.write(FileSender.NEW_L
dos.write(FileSender.NEW_L
dos.write(m_midlet.getPgcF
dos.write(FileSender.NEW_L
////////////////PGC file ---- the one which works..
dos.write(FileSender.PREFI
dos.write(sBoundary.getByt
dos.write(FileSender.NEW_L
String sContentDisposition = "Content-Disposition: form-data; name=\"" +
sName + "_pgc\"; filename=\"" + sPgcFileName + "\"";
dos.write(sContentDisposit
dos.write(FileSender.NEW_L
String sType = "Content-Type: application/octet-stream";
dos.write(sType.getBytes()
dos.write(FileSender.NEW_L
dos.write(FileSender.NEW_L
dos.write(m_midlet.getPgcF
dos.write(FileSender.NEW_L
Thanks in advance.
Praj
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is M. The Header Content-Length, Content Type is Missing Header is missing in your code.
All the headers will be parsed on the server side code(JSP or any other server side script) and the operation will take place based on the content received on the server side.
I am not sure abt the server side code you have written . But be sure the method getAttachedImage() returns the image properly by checking it directly on the mobile once . if its fine . Then all the consequences will work fine.
Let me know if you have any more problems