aspose file tools*
The moose likes Servlets and the fly likes upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "upload" Watch "upload" New topic
Author

upload

Relu Ovidiu
Greenhorn

Joined: Mar 18, 2004
Posts: 12
I use this code for upload:

public void doPost ...
{

.....
FileOutputStream fout = new FileOutputStream(cale+"/" + "file.txt");
final int BUFFER_SIZE = 8192;
....
ServletInputStream in = request.getInputStream();
....
}
try
{
int contentLength = request.getContentLength();
String contentType = request.getContentType();

ServletInputStream in = request.getInputStream();

byte[] buffer = new byte[BUFFER_SIZE];

int i=0;
int result1=0;
int result=1;
while (true)
{
i++;
if (i<=4)
result1 = in.readLine(buffer, 0, BUFFER_SIZE);
else
result = in.readLine(buffer, 0, BUFFER_SIZE);
if (result <= 0)
{
break;
}
if (i>4)
fout.write(buffer, 0, result);
}
}
catch (IOException e)
{
}
finally
{
fout.close();
}
The original txt file looks like this:
1
2
3

But the uploaded file looks like this:
-----------------------------7d41ae27e2c
Content-Disposition: form-data; name="fupload"; filename="C:\My Documents\test.txt"
Content-Type: text/plain

1
2
3
-----------------------------7d41ae27e2c--

I manage to skip the first 4 lines( with the i variable and the tests) but i can skip the last line (-----------------------------7d41ae27e2c)

Now, the uploaded file looks loke this:
1
2
3
-----------------------------7d41ae27e2c--

HOW CAN I UPLOAD THE FILE WITHOUT THE LAST LINE? DO YOU SEE OTHER SOLUTION OF UPLOADING?

THNX!
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Theres a lot more going on then you see right there. The easiest is to use Jakarta Commons FileUpload


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
 
subject: upload