aspose file tools*
The moose likes I/O and Streams and the fly likes UPloading a Big file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "UPloading a Big file" Watch "UPloading a Big file" New topic
Author

UPloading a Big file

Abhilesh Khatri
Ranch Hand

Joined: Oct 02, 2002
Posts: 39
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);

....
..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UPloading a Big file
 
Similar Threads
Brainy Upload Bean.
To Save a file in a different location
File Upload using JSP
File Upload Problem(Database and Dirctory)
How to Upload a image or video where it will be attached or keep in email?