aspose file tools*
The moose likes Servlets and the fly likes Image Upload issue using servlets and MultipartRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Image Upload issue using servlets and MultipartRequest" Watch "Image Upload issue using servlets and MultipartRequest" New topic
Author

Image Upload issue using servlets and MultipartRequest

Venkata Koritala
Greenhorn

Joined: Dec 18, 2009
Posts: 2
Hi,
We are using jsp's and Front servlets in our application. We have functionality where we need to upload an image and the uploaded image is converted into PSEG format and saved in database. Application will acccept images with .GIF extension only.
When user uploads an image, the GIF data of image is read as a byte array and the byte array is converted as a hexstring. The converted hexstring is then converted to PSEG format. Please find below the code.
MultipartRequest objMultiReq = null;
private boolean uploadImage(HttpServletRequest objReq, ImageDelegate objImage)
{
try
{
objMultiReq = new MultipartRequest(objReq, 1024000, 2);
}
catch(Exception exception )
{
exception.printStackTrace();
throw new GISMOException("8002_E",CLASS_NAME,ImageConstants.METHOD_UPLOADIMAGE,exception,exception.getMessage());
}
byte[] bImageData = objMultiReq.getByteArray(0); //Get the GIF image data
for(int i=0;i<bImageData.length;i++)
{
int uByte = bImageData[i];
uByte &= 0xff;
String hexStr = Integer.toHexString(uByte);
if("2c".equalsIgnoreCase(hexStr))
{
System.out.println("HERE!!!---->"+i);
}

System.out.print(hexStr+" ");
}
}
Our application is using an NDM server and two application servers. This NDM server is responsible for routing the request to either of the application server. We are getting an error when we are uploading an image and that too when the request is going to one particular server. If the request is going to another server the image uploads successfully.
When we tried printing the hex string we found difference in the strings that are developed by both the servers. The details are as follows
HEXSTRING FOR SUCCESSFULLY EXECUTED SERVER
47 49 46 38 39 61 24 0 33 0 f7 0 0 0 0 0 80 0 0 0 80 0 80 80 0 0 0 80 80 0 80 0 80 80 80 80 80 c0 c0 c0 ff 0 0 0 ff 0 ff ff 0 0 0 ff ff 0 ff 0 ff ff ff ff ff 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 66 0 0 99 0 0 cc 0 0 ff 0 33 0 0 33 33 0 33 66 0 33 99 0 33 cc 0 33 ff 0 66 0 0 66 33 0 66 66 0 66 99 0 66 cc 0 66 ff 0 99 0 0 99 33 0 99 66 0 99 99 0 99 cc 0 99 ff 0 cc 0 0 cc 33 0 cc 66 0 cc 99 0 cc cc 0 cc ff 0 ff 0 0 ff 33 0 ff 66 0 ff 99 0 ff cc 0 ff ff 33 0 0 33 0 33 33 0 66 33 0 99 33 0 cc 33 0 ff 33 33 0 33 33 33 33 33 66 33 33 99 33 33 cc 33 33 ff 33 66 0 33 66 33 33 66 66 33 66 99 33 66 cc 33 66 ff 33 99 0 33 99 33 33 99 66 33 99 99 33 99 cc 33 99 ff 33 cc 0 33 cc 33 33 cc 66 33 cc 99 33 cc cc 33 cc ff 33 ff 0 33 ff 33 33 ff 66 33 ff 99 33 ff cc 33 ff ff 66 0 0 66 0 33 66 0 66 66 0 99 66 0 cc 66 0 ff 66 33 0 66 33 33 66 33 66 66 33 99 66 33 cc 66 33 ff 66 66 0 66 66 33 66 66 66 66 66 99 66 66 cc 66 66 ff 66 99 0 66 99 33 66 99 66 66 99 99 66 99 cc 66 99 ff 66 cc 0 66 cc 33 66 cc 66 66 cc 99 66 cc cc 66 cc ff 66 ff 0 66 ff 33 66 ff 66 66 ff 99 66 ff cc 66 ff ff 99 0 0 99 0 33 99 0 66 99 0 99 99 0 cc 99 0 ff 99 33 0 99 33 33 99 33 66 99 33 99 99 33 cc 99 33 ff 99 66 0 99 66 33 99 66 66 99 66 99 99 66 cc 99 66 ff 99 99 0 99 99 33 99 99 66 99 99 99 99 99 cc 99 99 ff 99 cc 0 99 cc 33 99 cc 66 99 cc 99 99 cc cc 99 cc ff 99 ff 0 99 ff 33 99 ff 66 99 ff 99 99 ff cc 99 ff ff cc 0 0 cc 0 33 cc 0 66 cc 0 99 cc 0 cc cc 0 ff cc 33 0 cc 33 33 cc 33 66 cc 33 99 cc 33 cc cc 33 ff cc 66 0 cc 66 33 cc 66 66 cc 66 99 cc 66 cc cc 66 ff cc 99 0 cc 99 33 cc 99 66 cc 99 99 cc 99 cc cc 99 ff cc cc 0 cc cc 33 cc cc 66 cc cc 99 cc cc cc cc cc ff cc ff 0 cc ff 33 cc ff 66 cc ff 99 cc ff cc cc ff ff ff 0 0 ff 0 33 ff 0 66 ff 0 99 ff 0 cc ff 0 ff ff 33 0 ff 33 33 ff 33 66 ff 33 99 ff 33 cc ff 33 ff ff 66 0 ff 66 33 ff 66 66 ff 66 99 ff 66 cc ff 66 ff ff 99 0 ff 99 33 ff 99 66 ff 99 99 ff 99 cc ff 99 ff ff cc 0 ff cc 33 ff cc 66 ff cc 99 ff cc cc ff cc ff ff ff 0 ff ff 33 ff ff 66 ff ff 99 ff ff cc ff ff ff 21 f9 4 1 0 0 10 0
HEX STRING FOR SERVER THAT IS HAVING A PROBLEM
47 49 46 38 39 61 24 0 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 66 0 0 0 0 33 0 0 33 33 0 33 66 0 33 33 33 66 0 0 66 33 0 66 66 0 66 66 66 0 0 0 0 0 0 0 0 0 cc 99 0 0 0 0 0 0 0 0 33 0 0 33 0 33 33 0 66 33 0 0 0 33 0 33 33 33 33 33 66 33 33 33 33 66 0 33 66 33 33 66 66 33 66 66 66 33 33 33 33 33 33 33 33 33 cc 99 33 33 33 33 33 33 33 33 66 0 0 66 0 33 66 0 66 66 0 0 0 33 0 66 33 33 66 33 66 66 33 33 33 66 0 66 66 33 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 cc 99 66 66 66 66 66 66 66 66 0 33 66 0 cc 99 0 33 0 33 66 33 cc 99 33 66 0 33 66 66 cc 99 66 33 66 33 66 33 66 0 0 33 66 0 0 33 0 33 66 33 33 66 0 33 66 66 66 cc 99 33 cc 99 66 cc 99 cc 99 33 66 33 66 0 0 33 66 0 0 33 0 33 66 33 33 66 0 33 66 66 66 33 66 33 66 33 66 1 0 0 10 0


Can anyone please let us know whether the byte array of the image uploaded should be same irrespective of the application server and also what might be the possible reason that causes this difference.

Thanks in Advance

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

"Techie Mukesh", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Upload issue using servlets and MultipartRequest