E
Emery Z. Balint Jr.
My objective here is to have a place where users could upload an image file
to the server. I'm using a form with encType set to multipart/form-data and
I've read up on how to extract the data that comes through. Easy enough,
except that for some reason when I get to the part of extracting the files,
I get corrupt data.
Below I've tried using PrintWriter (which works the best so far)
FileOutputStreams and even nio with a ByteBuffer. Anything that writes
binary stream hasn't worked at all, the file sizes that occur are several
times larger than the original, hence why I stuck with PrintWriter. The test
file written with this code below ends up having exactly the same file size
as the original, but again with corrupt data. I'm a little lost at this
point, as according to most documents I found on the subject I should be
doing this correctly. Many thanks in advance for any assistance!
Emery.
/\^/\^/\
Sun Certified Java Programmer
www.websamba.com/javarobotics/
E-stronomy - Astronomical Resources
www.websamba.com/e-stronomy/
Talking with Tonz - Dance/Alternative Music
www.soundclick.com/talkingwithtonz/
File file1 = new File("tester.png");
file1.createNewFile();
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file1)));
while (lineSize!=-1 && !nextLine.startsWith(delimiter)) {
lineSize = in.readLine(inLine, 0, 1024);
if ((lineSize==delimiter.length()+4)
&& (new String(inLine, 0, lineSize).startsWith(delimiter))) {
nextLine = nextLine.substring(0, nextLine.length()-2);
pw.print(nextLine);
} else {
pw.print(nextLine);
}
nextLine = new String(inLine, 0, lineSize);
}
pw.close();
to the server. I'm using a form with encType set to multipart/form-data and
I've read up on how to extract the data that comes through. Easy enough,
except that for some reason when I get to the part of extracting the files,
I get corrupt data.
Below I've tried using PrintWriter (which works the best so far)
FileOutputStreams and even nio with a ByteBuffer. Anything that writes
binary stream hasn't worked at all, the file sizes that occur are several
times larger than the original, hence why I stuck with PrintWriter. The test
file written with this code below ends up having exactly the same file size
as the original, but again with corrupt data. I'm a little lost at this
point, as according to most documents I found on the subject I should be
doing this correctly. Many thanks in advance for any assistance!
Emery.
/\^/\^/\
Sun Certified Java Programmer
www.websamba.com/javarobotics/
E-stronomy - Astronomical Resources
www.websamba.com/e-stronomy/
Talking with Tonz - Dance/Alternative Music
www.soundclick.com/talkingwithtonz/
File file1 = new File("tester.png");
file1.createNewFile();
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file1)));
while (lineSize!=-1 && !nextLine.startsWith(delimiter)) {
lineSize = in.readLine(inLine, 0, 1024);
if ((lineSize==delimiter.length()+4)
&& (new String(inLine, 0, lineSize).startsWith(delimiter))) {
nextLine = nextLine.substring(0, nextLine.length()-2);
pw.print(nextLine);
} else {
pw.print(nextLine);
}
nextLine = new String(inLine, 0, lineSize);
}
pw.close();