image upload
hello
I read a file from the request object (myImage.jpg) to save it on the server
of my web application
thats is ok and works fine
after upload and write the file on the server Itry to diplay the uploaded image one see image with very very bad qulity
what shoud be the problem
here is the code
public void doUpload(HttpServletRequest request)
{
try
{
setSavePath(request.getSession().getServletContext().getRealPath("/")+"\\tempData\\");
ServletInputStream in = request.getInputStream();
byte[] line = new byte[128];
int i = in.readLine(line, 0, 128);
if (i < 3) return;
int boundaryLength = i - 2;
String boundary = new String(line, 0, boundaryLength); //-2 discards the newline character
fields = new Hashtable();
while (i != -1) {
String newLine = new String(line, 0, i);
setContentType(new String(line, 0, i-2));
if (newLine.startsWith("Content-Disposition: form-data; name=\"")) {
if (newLine.indexOf("filename=\"") != -1) {
setFilename(new String(line, 0, i-2));
if (filename==null || filename.equalsIgnoreCase("") || filename.equalsIgnoreCase(" ") || filename.length()< 1)
return;
//this is the file content
i = in.readLine(line, 0, 128);
//setContentType(new String(line, 0, i-2));
i = in.readLine(line, 0, 128);
// blank line
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
String IDmod = "";
int _x_ = app.org.AppConstants.AdID.indexOf("_");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter((savePath==null? "" : savePath) + filename)));
while (i != -1 && !newLine.startsWith(boundary)) {
i = in.readLine(line, 0, 128);
if ((i==boundaryLength+2 || i==boundaryLength+4) // + 4 is eof
&& (new String(line, 0, i).startsWith(boundary)))
pw.print(newLine.substring(0, newLine.length()-2));
else
pw.print(newLine);
newLine = new String(line, 0, i);
}
pw.close();
}
...................
can man here usee ImageInputStream an who
thanks