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!