How to fixing boundaries of file in inputstream of uploading files in java servlet?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, March 23, 2001 01:14 PM

I coded for one or more files Upload to Server througth Java Servlets. After run code, files were uploaded. Some files(TXT, WKS, JAVA, BMP, HTML, XML) are OK. Some files (DOC, GIF, JPG, PDF, ZIP, MDB) were not opened, when I was tried to open in windows. Please suggest me, if you find any error in my code or any changes required. The code I wrote like this. inputstream = new DataInputStream(request.getInputStream()); fileContent = new String(db); String boundary = contentType.substring(lastIndex + 1,contentType.length()); String fileName = fileContent.substring(fileContent.indexOf("filename="",indx)+10); pos = fileContent.indexOf ("filename="",indx); pos = fileContent.indexOf   More>>

I coded for one or more files Upload to Server througth Java Servlets. After run code, files were uploaded. Some files(TXT, WKS, JAVA, BMP, HTML, XML) are OK. Some files (DOC, GIF, JPG, PDF, ZIP, MDB) were not opened, when I was tried to open in windows. Please suggest me, if you find any error in my code or any changes required. The code I wrote like this.

			
inputstream = new DataInputStream(request.getInputStream());
fileContent = new String(db);
String boundary = contentType.substring(lastIndex + 1,contentType.length());
String fileName = fileContent.substring(fileContent.indexOf("filename="",indx)+10);
pos = fileContent.indexOf ("filename="",indx);
pos = fileContent.indexOf("
",pos)+1;
pos = fileContent.indexOf("
",pos)+1;
pos = fileContent.indexOf("
",pos)+1;

int boundaryPoint = fileContent.indexOf(boundary,pos)-4;

String file1 = fileContent.substring(pos,boundaryPoint);
   <<Less

Re: How to fixing boundaries of file in inputstream of uploading files in java servlet?

Posted By:   Tim_Rohaly  
Posted On:   Monday, April 23, 2001 01:15 PM

Well, your code makes no sense because you have left out
all the key parts. Such as, how do you get the data out of
the input stream? What is the db varibable? etc.
It looks like you are treating all data as text, reading it in
a line at a time, using strings, and searching for line terminators.
This will not work with binary data such as DOC, GIF, JPG etc.
file types. You must treat all data (even text) as binary.
Your code should be rewritten to do this properly.
About | Sitemap | Contact