Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Different sizes at different times of downloading of file using servlets.  RSS feed

 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using below code to download file using servlets.But when i am downloading file for first time it is showing exact file size,from second time it is showing multiple of 2 to the previous size of file.I want to get file size as same for every time of downloading.Can any one please help me to do that.


Here filePath is the path of the file which i want to download.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was my problem I would start by:

1. Get the File size, log it, and use setContentLength() to set the Content-Length header in the response.
2. log all of those exceptions.

Bill
 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william,
I have tried setting content-length.If i set the content length i am getting only 1kb data of file instead of whole zip file.when i am trying to open that zip it is showing that the zip got corrupted.can anyone please help me how to resolve this..

Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I call your attention to item 2. log all the exceptions

There is no way that setting Content-Length to the correct file size is going to truncate your download at 1K.

Bill
 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william,
I have logged all the eceptions.I did not get any exception.Its downloading fine.But when downloading,file size is getting multiple of 2 of before downloading file size.
I am using following code to set content-length.

Can anyone please help me to resolve this.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logically, if the servlet is sending the correct content, the fault must lie on the client side. Doubling the size sounds like the client side is appending to the existing file.

If this was my problem I would examine a doubled file with a programmer's editor capable of displaying hex, particularly at the point where the file is supposed to end.

What is this supposed to do:



Bill
 
Mahender Parkipandla
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you need to use below code in your servlet for caching not to happen with response.

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!