I am trying to upload a file to a server using a HTTP Post Client.
At the client side I have a Java program that reads it and posts it to the
servlet.
The servlet reads the incoming stream of data and writes it to the disk. Simple
enough.
This works like a charm most of the times , but in certain cases when the file
size exceeds 4-5 Meg , it fails.
I tweaked it a little bit but still could'nt figure out what's causing it to
fail.
Any help , suggestion or pointer is appreciated.
Here's the code
Client Side
String url ="http://benetestw2k/servlet/UploadServlet?filename="+args[0];
URL theURL = new URL(url);
HttpURLConnection theConnection =
(HttpURLConnection)theURL.openConnection();
theConnection.setDoOutput(true);
theConnection.setUseCaches(false);
PrintWriter out = new PrintWriter(theConnection.getOutputStream());
// Read File
String fileContents = "";
String line = null;
FileReader f1 = new FileReader(args[0]);
BufferedReader theReader = new BufferedReader(f1);
// Send each line to Servlet
while ((line = theReader.readLine()) != null)
{
out.println(line);
}
Server Side
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
BufferedWriter uploadFile = null;
filename = request.getParameter("filename");
String uploadFileName = uploadDirectory + '\\' + filename;
try
{
// Get the Input Stream
ServletInputStream input = request.getInputStream();
BufferedReader theReader =
new BufferedReader(new InputStreamReader(input));
uploadFile = new BufferedWriter(new FileWriter(uploadFileName));
String line = null;
while ((line = theReader.readLine()) != null)
{
uploadFile.write(line);
uploadFile.newLine();
}
Thanks in advance
Santosh
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets