• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UPloading a Big file

 
Abhilesh Khatri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to upload a big file of size 3 MB.
I am using readLine(byte, int, byte) to upload this file.
It works fine. But takes about an hour to upload the file, which is unacceptable. Performance is crucial for our application.
Can any one suggest how to upload the file and achieve optimal performance
I am pasting the code snippet for your reference
ServletInputStream in = request.getInputStream();
byte[] line = new byte[128];
int i = in.readLine(line, 0, 128);
if (i < 3){
return null;
}
int boundaryLength = i - 2;
String boundary = new String(line, 0, boundaryLength);
fields = new Hashtable();

while (i != -1) {

fileData = new String();
String newLine = new String(line, 0, i);

if (newLine.startsWith("Content-Disposition: form-data; name=\""))
{
if (newLine.indexOf("filename=\"") != -1)
{
setFilename(new String(line, 0, i-2));

i = in.readLine(line, 0, 128);
setContentType(new String(line, 0, i-2));
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
fileData+=newLine;
while (i != -1 && !newLine.startsWith(boundary)) {
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
fileData+=newLine;
}
}
else {
int pos = newLine.indexOf("name=\"");
String fieldName = newLine.substring(pos+6, newLine.length()-3);
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
StringBuffer fieldValue = new StringBuffer(128);
while (i != -1 && !newLine.startsWith(boundary)) {
i = in.readLine(line, 0, 128);
if ((i==boundaryLength+2 || i==boundaryLength+4)
&& (new String(line, 0, i).startsWith(boundary)))
fieldValue.append(newLine.substring(0, newLine.length()-2));
elsefieldValue.append(newLine);
newLine = new String(line, 0, i);
}
fields.put(fieldName, fieldValue.toString());
}
}
i = in.readLine(line, 0, 128);

....
..
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic