• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Slow File Upload with Large File

Jim Otte
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following problem- I have a servlet which receives a multi part post which then uses the oreilly servlet package to parse the content- and this works great for files up to about 2 or 3 meg- very quick and I get the file. However, when I increase the file size (eg 8 meg) the process slows down a LOT(almost as if it reaches a point that is quick then ...slow). I tried increasing buffer sizes (uses BufferedServletInputStream) and just about everything I could imagine (even changing it so it does not write file to disk) but to no avail- I tracked it down to 1 method- the fill() in the BufferedServletStream class- in particular the :
int i = in.read(buf, 0, buf.length);
where in is the ServletInputStream;
I thought maybe the oreilly classes might be the prob- so I did a very crude post-
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
File file = new File("outputFile.txt");
FileOutputStream out = new FileOutputStream(file);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(request.getContentLength());
byte[] buf = new byte[1024*1024];//128
int read;
InputStream in2 = new BufferedInputStream(request.getInputStream());
while ((read = in2.read(buf)) != -1) {
baos.write(buf, 0, read);
byte[] value = baos.toByteArray();
String first = new String(value);

This was just to see what was getting read- and also very quick with small files- long with bigger files (almost exponentially)- so prob was not oreilly classes but how ServletInputStream reads in data- so my ?-
1. Is there a way to speed this up with larger files?
2. Out of curiosity, is this great slowdown due to decrypting the inputStream?
If there is no way around it then I guess FTP will be the answer....
Thanks to whoever can answer these ?'s
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic