Solved

Error while Downloading zip file using servlet which containing JPEG and xml

Posted on 2008-10-30
2
654 Views
Last Modified: 2013-11-24
I am Downloading Zip file using servlet, but its giving me error "EP0011[1].zip: Unexpected end of archive
", the zip file is perfetc but its giving error at the time of downloading at client side, code snippet is attached with this error

String imageFileName1 = "D://test.zip";
input = new BufferedInputStream(new FileInputStream(new File(imageFileName1)));
	      
	      response.reset();
	      response.setContentLength(decoded.length);
	      //response.setContentType("image/jpeg");
	      response.setContentType("application/zip");
	      response.setHeader("Content-disposition", "attachment; filename=\"" + imageFileName1 + "\"");
	      int count;
	      System.out.println("Length : "+imageFileName1.getBytes().length);
	      byte[] buffer = new byte[300000];
	      
	      while ((count = input.read(buffer)) > 0)
	    	    out.write(buffer, 0, count);

Open in new window

0
Comment
Question by:ASHISHRAIK11
  • 2
2 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 22851274
You are using out.write to chuck out the contents of a file, that's OK. But you're telling the browser that the content length of the stream is

          response.setContentLength(decoded.length);

I'm not sure what value decoded.length has, but the stream simply needs the size of the file, not the size when it is decompressed.
0
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
ID: 22851297
>>You are using out.write to chuck out the contents of a file, that's OK

Should have read :-

You are using out.write to chuck out the contents of a file, that's not OK, since it has to go via response.

IE: The archive is being truncated because of a) no data is being written or b) the content length is incorrect.

Sorry about the mixup.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
word0 challenge 3 101
wordcount challenge 11 133
jsp insert to database example 2 47
Select statement in @Query (JPA Repository) - SpringMVC 2 14
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question