Re: Tomcat 5.5 creates 0 byte files
You all right about ESXi issue, df -k shows only the virtual machines storage and that error is occured because of the max number of files allowed by OS. I will try out the things Andre, Pid and Chris suggested and then i'll hopefully write you good news about my problem. Again thanks for all your help. I'll be posting soon about the results. Best, On Fri, Jul 2, 2010 at 5:27 PM, André Warnier a...@ice-sa.com wrote: Murat Birben wrote: Actually i'm not familiar with the interanls of enctype=multipart/form-data thing. I think, i should read about this right? Right. Start here : http://www.w3.org/TR/html401/interact/forms.html 17.13 Form submission Then graduate to this if you really want to know the details : RFC 2045 http://www.ietf.org/rfc/rfc2045.txt But, as a summary : With the form you showed earlier, what the browser will send to the server is a block of text data looking (approximately) like this : (start) POST /ResourceUploadServlet HTTP/1.1 Content-type: multipart/form-data; boundary=-something .. more header lines, followed by one empty line .. -something Content-type: text/plain Content-disposition: form-data; name=FileName Content-length: 18 some-file-name.pdf -something Content-type: text/plain Content-disposition: form-data; name=Path Content-length: 10 /some/path -something Content-type: application/pdf Content-disposition: form-data; name=Content; filename=some/path/and/file-name.pdf Content-length: 132456 Content-transfer-encoding: Base64 pcEAJ2AJBAAA+BK/EAAABgAAHAgAAA4AYmpiauvI68gA AAAHBBYALhAAAImiAACJogAAHAD//w8A AAD//w8AAAD//w8AAKQAAMADwAMAAMAD wAMAAADAAwAAAMADwAMAABQAANQD3AYA AADcBgAAANwG3AYAAAwAAADoBgAADNQDrAwAAP4ABwAA AAAHAAcABwAH2wcAAADbBwAAANsH KwwAAAItDC0MLQwtDC0MLQwAACQA AACqDQAAaAIAABIQAAByUQwAABUAwAMAAADbBwAA AADbBwAAANsH2wcAAADbBwAAAFEM AADAAwAAAMADAAcHAADbZgwAABYAAAD3 .. and many similar lines ... (end) Each input of the form is going to result in one of the form-data blocks above. The input type=file will result in some very large block like the last one, which contains the binary data of the file, encoded in Base64 encoding. Tomcat 5.5 (and 6.0), natively, do not contain any standard code capable of parsing such a POST data format and returning it nicely to your servlet. (And you cannot just do a request.getParameter('Content') either.) (but with Tomcat 7.0 however you should be able to). To handle this kind of POST with Tomcat 5.5 or 6.0, you have either to do the work yourself (not recommended), or use something like FileUpload to do it. But you cannot just read the body of the request, and copy it to a disk file. Or rather, you can, but then you will have the whole block above in your disk file. I do not remember how the FileUpload module really works, but it allows you to retrieve each of the blocks above (=form parameters) independently, and it will do all the decoding for you. For the file part (named Content), it probably gives you already a Stream, from which you can read to retrieve the (decoded) content of the file. THAT is what you should be copying to a disk file. Got the general idea ? And, as pid was saying, the FileUpload documentation should certainly provide some good examples. But, no matter how you do this, read this 3 times /NEVER/ accept the path or the filename that the user is entering in the form, to just write this file to disk. /read this 3 times Remember what the user has entered, and write it somewhere as a text. But create a path and a (unique) filename yourself, in your servlet, to write the file. That will protect you not only against nasty people trying to crash your server, but also against innocent users entering file names with spaces in them, or funny characters that are illegal in a filename on your system, or re-using a filename that already exists. (to name just a few of the things that can happen). All that still does not tell us why your servlet creates 0-size files, but maybe with the above explanation you can figure this out yourself. My scenario : - your first getParameter() call sucks in the whole POST (all the above) - your next getParameter() calls do not have anything else to get, and return null - by the time you try to read the body of the POST, there is nothing left, so you also get null - and then you write this (null) to the output file, and you get a null-size file. Repeat the above cycle once for each POST.
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } signature.asc Description: OpenPGP digital signature
Re: Tomcat 5.5 creates 0 byte files
Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Hi. I am not good enough in those things to evaluate your code, but here are a couple of tips to do what you seem to want to do. Have a look at : - up to Tomcat 5.5, there was an application called DAV available with Tomcat. That is something designed to do just that : allow users to upload/download) files to/from the server using Tomcat. With some caveats, this works together with what Microsoft calls web folders, and allows Windows workstation users to see folders on the server within their Windows Explorer (like network shares), and copy/move files to/from there. (It also works, and usually better, with other client DAV implementations). - see http://commons.apache.org/fileupload/ (this may even be included in Tomcat by now; I think I heard something about this a while ago) The point is : allowing users to upload files to the server, and allowing them to specify a path on the server, is dangerous and difficult to do right. Better to use something that is already ready and debugged. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 11:00, André Warnier wrote: - up to Tomcat 5.5, there was an application called DAV available with Tomcat. The WebDAV servlet is still there in Tomcat 7. We just removed the example app from 6 onwards. - see http://commons.apache.org/fileupload/ (this may even be included in Tomcat by now; I think I heard something about this a while ago) File upload is part of the Servlet 3 spec so that feature is in Tomact 7. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
André Warnier wrote: ... The point is : allowing users to upload files to the server, and allowing them to specify a path on the server, is dangerous and difficult to do right. Better to use something that is already ready and debugged. Let me be more explicit, after having just a quick look at your code : enter path : /etc enter filename : passwd or more devious : enter path : /some/innocent/path enter filename : ../../../../../etc/passwd and your server would not last 2 minutes on the Internet. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
Mark Thomas wrote: On 02/07/2010 11:00, André Warnier wrote: - up to Tomcat 5.5, there was an application called DAV available with Tomcat. The WebDAV servlet is still there in Tomcat 7. We just removed the example app from 6 onwards. Noted, thanks. But it seems hard to find. I do not see any obvious links to it on http://tomcat.apache.org/tomcat-7.0-doc/index.html If I wanted to set this up, where do I start ? (I have never used it personally with Tomcat. Assuming I wanted to, is it safe, like production-safe (or like Apache's mod_dav safe) ?) - see http://commons.apache.org/fileupload/ (this may even be included in Tomcat by now; I think I heard something about this a while ago) File upload is part of the Servlet 3 spec so that feature is in Tomact 7. Ah. So that means that Tomcat can now handle multipart/form-data POSTs in general ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
Yes 0 byte files are causing the disk to run out of space @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN signature.asc Description: OpenPGP digital signature
Re: Tomcat 5.5 creates 0 byte files
I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN -- Murat BIRBEN
RE: Tomcat 5.5 creates 0 byte files
you can also try the oreilly file upload api, I have used it in many projects without issue http://www.servlets.com/cos/ (download) http://java.itags.org/java-essentials/11012/ (an example) From: users-return-214291-racarlson=mediacomcc@tomcat.apache.org [users-return-214291-racarlson=mediacomcc@tomcat.apache.org] On Behalf Of Murat Birben [muratbir...@gmail.com] Sent: Friday, July 02, 2010 6:01 AM To: Tomcat Users List; p...@pidster.com Subject: Re: Tomcat 5.5 creates 0 byte files Yes 0 byte files are causing the disk to run out of space @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
I've tried apache.commons.fileupload api but the result doesn't change. I set the selenium waitForPageToLoad prop very small to produce the problem and when time exceeded test fails and thousands of 0 bytes are generated. I'll try the oreilly fileupload api too but it seems to me as the reason is not about the upload api. Is there anyone has another idea about this? On Fri, Jul 2, 2010 at 3:19 PM, Ralph Carlson racarl...@mediacomcc.comwrote: you can also try the oreilly file upload api, I have used it in many projects without issue http://www.servlets.com/cos/ (download) http://java.itags.org/java-essentials/11012/ (an example) From: users-return-214291-racarlson=mediacomcc@tomcat.apache.org[users-return-214291-racarlson= mediacomcc@tomcat.apache.org] On Behalf Of Murat Birben [ muratbir...@gmail.com] Sent: Friday, July 02, 2010 6:01 AM To: Tomcat Users List; p...@pidster.com Subject: Re: Tomcat 5.5 creates 0 byte files Yes 0 byte files are causing the disk to run out of space @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- Murat BIRBEN
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 12:20, Murat Birben wrote: I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created What is your OS and exact version? p On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN -- Murat BIRBEN signature.asc Description: OpenPGP digital signature
Re: Tomcat 5.5 creates 0 byte files
ubuntu 8.04 server On Fri, Jul 2, 2010 at 3:50 PM, Pid p...@pidster.com wrote: On 02/07/2010 12:20, Murat Birben wrote: I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created What is your OS and exact version? p On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN -- Murat BIRBEN -- Murat BIRBEN
Re: Tomcat 5.5 creates 0 byte files
Murat Birben wrote: I've tried apache.commons.fileupload api but the result doesn't change. I set the selenium waitForPageToLoad prop very small to produce the problem and when time exceeded test fails and thousands of 0 bytes are generated. I'll try the oreilly fileupload api too but it seems to me as the reason is not about the upload api. Is there anyone has another idea about this? Murat, I have the feeling that you are not really familiar with the underlying HTTP mechanisms for multipart posts and/or file uploads. Can you post here a copy of the html form used by the client ? (take out the target server name etc..) - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
Ok, here is the html form: form action=ResourceUploadServlet method=POST enctype=multipart/form-data input type=file name=Content / FileName :input type=text name=FileName / Path:input type=text name=Path / input type=submit value=Submit / /form Thanks for your concern, On Fri, Jul 2, 2010 at 4:02 PM, André Warnier a...@ice-sa.com wrote: Murat Birben wrote: I've tried apache.commons.fileupload api but the result doesn't change. I set the selenium waitForPageToLoad prop very small to produce the problem and when time exceeded test fails and thousands of 0 bytes are generated. I'll try the oreilly fileupload api too but it seems to me as the reason is not about the upload api. Is there anyone has another idea about this? Murat, I have the feeling that you are not really familiar with the underlying HTTP mechanisms for multipart posts and/or file uploads. Can you post here a copy of the html form used by the client ? (take out the target server name etc..) - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- Murat BIRBEN
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 14:02, Murat Birben wrote: ubuntu 8.04 server What does the command 'df -k' report? Please paste the results. p On Fri, Jul 2, 2010 at 3:50 PM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 12:20, Murat Birben wrote: I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created What is your OS and exact version? p On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; }
Re: Tomcat 5.5 creates 0 byte files
Murat Birben wrote: Ok, here is the html form: form action=ResourceUploadServlet method=POST enctype=multipart/form-data input type=file name=Content / FileName :input type=text name=FileName / Path:input type=text name=Path / input type=submit value=Submit / /form Ok. First, you should probably change the form tag as follows : form action=/ResourceUploadServlet method=POST enctype=multipart/form-data Next: When the browser sends this to the server, it will do this using a particular format, similar to the (internal) format of an email with attachments. This is what the part : enctype=multipart/form-data is all about. Are you familiar with this ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 14:21, André Warnier wrote: Murat Birben wrote: Ok, here is the html form: form action=ResourceUploadServlet method=POST enctype=multipart/form-data input type=file name=Content / FileName :input type=text name=FileName / Path:input type=text name=Path / input type=submit value=Submit / /form Ok. First, you should probably change the form tag as follows : form action=/ResourceUploadServlet method=POST enctype=multipart/form-data Better: action=%= request.getContextPath() %/ResourceUploadServlet Even better: action=%= response.encodeURI(request.getContextPath() + '/ResourceUploadServlet') % p Next: When the browser sends this to the server, it will do this using a particular format, similar to the (internal) format of an email with attachments. This is what the part : enctype=multipart/form-data is all about. Are you familiar with this ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org signature.asc Description: OpenPGP digital signature
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 13:47, Murat Birben wrote: I've tried apache.commons.fileupload api but the result doesn't change. I set the selenium waitForPageToLoad prop very small to produce the problem and when time exceeded test fails and thousands of 0 bytes are generated. I'll try the oreilly fileupload api too but it seems to me as the reason is not about the upload api. Is there anyone has another idea about this? It's been a while, since I used commons-file-upload, but I remember the examples being fairly comprehensive. The streaming API seemed nicer to use. I don't remember being forced to write a file to the disk, maybe you can catch the error and not write the file at all. p On Fri, Jul 2, 2010 at 3:19 PM, Ralph Carlson racarl...@mediacomcc.comwrote: you can also try the oreilly file upload api, I have used it in many projects without issue http://www.servlets.com/cos/ (download) http://java.itags.org/java-essentials/11012/ (an example) From: users-return-214291-racarlson=mediacomcc@tomcat.apache.org[users-return-214291-racarlson= mediacomcc@tomcat.apache.org] On Behalf Of Murat Birben [ muratbir...@gmail.com] Sent: Friday, July 02, 2010 6:01 AM To: Tomcat Users List; p...@pidster.com Subject: Re: Tomcat 5.5 creates 0 byte files Yes 0 byte files are causing the disk to run out of space @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf); fileOutputStream.flush(); iTotelLen += iBufLen; if (fileInputStream.available() iReadLen) { iReadLen = fileInputStream.available(); break; } } byte[] tempbBuf = new byte[iReadLen]; fileInputStream.read(tempbBuf, 0, iReadLen); fileOutputStream.write(tempbBuf); } catch (IOException ex) { ex.printStackTrace(); } finally { fileOutputStream.close(); fileInputStream.close(); if (fFile.exists()) { fFile.delete(); } } -- Murat BIRBEN - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org signature.asc Description: OpenPGP digital signature
Re: Tomcat 5.5 creates 0 byte files
It is a virtual machine on ESXi so df shows me the whole storage I think. Is there any other way to see the disk usage for virtual machines? On Fri, Jul 2, 2010 at 4:20 PM, Pid p...@pidster.com wrote: On 02/07/2010 14:02, Murat Birben wrote: ubuntu 8.04 server What does the command 'df -k' report? Please paste the results. p On Fri, Jul 2, 2010 at 3:50 PM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 12:20, Murat Birben wrote: I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created What is your OS and exact version? p On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if (strPath.charAt(index) != '/') { strPath += /; } if (!new File(strPath).exists()) { new File(strPath).mkdirs(); } File file = new File(strPath + strFileName); fileOutputStream = new FileOutputStream(file); fileInputStream = new FileInputStream(fFile); byte[] bBuf = new byte[1024]; int iBufLen = 0; int iReadLen = 1024; int iTotelLen = 0; /*read 1024 bytes at a time*/ while ((iBufLen = fileInputStream.read(bBuf)) != -1) { fileOutputStream.write(bBuf);
Re: Tomcat 5.5 creates 0 byte files
Actually i'm not familiar with the interanls of enctype=multipart/form-data thing. I think, i should read about this right? By the way i'll change the form tag as you and Pid suggested. Thanks, On Fri, Jul 2, 2010 at 4:21 PM, André Warnier a...@ice-sa.com wrote: Murat Birben wrote: Ok, here is the html form: form action=ResourceUploadServlet method=POST enctype=multipart/form-data input type=file name=Content / FileName :input type=text name=FileName / Path:input type=text name=Path / input type=submit value=Submit / /form Ok. First, you should probably change the form tag as follows : form action=/ResourceUploadServlet method=POST enctype=multipart/form-data Next: When the browser sends this to the server, it will do this using a particular format, similar to the (internal) format of an email with attachments. This is what the part : enctype=multipart/form-data is all about. Are you familiar with this ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- Murat BIRBEN
Re: Tomcat 5.5 creates 0 byte files
On 02/07/2010 14:33, Murat Birben wrote: It is a virtual machine on ESXi so df shows me the whole storage I Does it? I'm not sure it does. think. Is there any other way to see the disk usage for virtual machines? That's a question I can't answer I'm afraid. p On Fri, Jul 2, 2010 at 4:20 PM, Pid p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 14:02, Murat Birben wrote: ubuntu 8.04 server What does the command 'df -k' report? Please paste the results. p On Fri, Jul 2, 2010 at 3:50 PM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 12:20, Murat Birben wrote: I'm getting There is no space left on disk message when i try to do some work on the server after this 0 byte files are created What is your OS and exact version? p On Fri, Jul 2, 2010 at 1:13 PM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 11:01, Murat Birben wrote: Yes 0 byte files are causing the disk to run out of space You understand my surprise? Are you sure the disk is running out of space, or is it that the number of files permitted in a directory has been exceeded? p @Andre Warnier I'm not actually saving files on the server. I just tried to simplify my problem and tried that simple code. Now i'll give a try to apache fileupload api, thanks for advice On Fri, Jul 2, 2010 at 11:52 AM, Pid p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com mailto:p...@pidster.com wrote: On 02/07/2010 09:43, Murat Birben wrote: Hi all, I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and *when a timeout occurs in the selenium test *tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this? Thousands of 0 byte files are causing the disk to run out of space? p My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6 Thanks, Here is the code snippet that i use File fFile = null; FileOutputStream fileOutputStream = null; FileInputStream fileInputStream = null; try { String strFileName = request.getParameter(FileName); String strPath = request.getParameter(Path); //String strMediaType = request.getParameter(MediaType); //String strDescription = request.getParameter(Description); fFile = (File) request.getAttribute(Content); int index = strPath.length() - 1; //If the user forgets to put the last / for the path... We put it for him/her if
Re: Tomcat 5.5 creates 0 byte files
Murat Birben wrote: Actually i'm not familiar with the interanls of enctype=multipart/form-data thing. I think, i should read about this right? Right. Start here : http://www.w3.org/TR/html401/interact/forms.html 17.13 Form submission Then graduate to this if you really want to know the details : RFC 2045 http://www.ietf.org/rfc/rfc2045.txt But, as a summary : With the form you showed earlier, what the browser will send to the server is a block of text data looking (approximately) like this : (start) POST /ResourceUploadServlet HTTP/1.1 Content-type: multipart/form-data; boundary=-something .. more header lines, followed by one empty line .. -something Content-type: text/plain Content-disposition: form-data; name=FileName Content-length: 18 some-file-name.pdf -something Content-type: text/plain Content-disposition: form-data; name=Path Content-length: 10 /some/path -something Content-type: application/pdf Content-disposition: form-data; name=Content; filename=some/path/and/file-name.pdf Content-length: 132456 Content-transfer-encoding: Base64 pcEAJ2AJBAAA+BK/EAAABgAAHAgAAA4AYmpiauvI68gA AAAHBBYALhAAAImiAACJogAAHAD//w8A AAD//w8AAAD//w8AAKQAAMADwAMAAMAD wAMAAADAAwAAAMADwAMAABQAANQD3AYA AADcBgAAANwG3AYAAAwAAADoBgAADNQDrAwAAP4ABwAA AAAHAAcABwAH2wcAAADbBwAAANsH KwwAAAItDC0MLQwtDC0MLQwAACQA AACqDQAAaAIAABIQAAByUQwAABUAwAMAAADbBwAA AADbBwAAANsH2wcAAADbBwAAAFEM AADAAwAAAMADAAcHAADbZgwAABYAAAD3 .. and many similar lines ... (end) Each input of the form is going to result in one of the form-data blocks above. The input type=file will result in some very large block like the last one, which contains the binary data of the file, encoded in Base64 encoding. Tomcat 5.5 (and 6.0), natively, do not contain any standard code capable of parsing such a POST data format and returning it nicely to your servlet. (And you cannot just do a request.getParameter('Content') either.) (but with Tomcat 7.0 however you should be able to). To handle this kind of POST with Tomcat 5.5 or 6.0, you have either to do the work yourself (not recommended), or use something like FileUpload to do it. But you cannot just read the body of the request, and copy it to a disk file. Or rather, you can, but then you will have the whole block above in your disk file. I do not remember how the FileUpload module really works, but it allows you to retrieve each of the blocks above (=form parameters) independently, and it will do all the decoding for you. For the file part (named Content), it probably gives you already a Stream, from which you can read to retrieve the (decoded) content of the file. THAT is what you should be copying to a disk file. Got the general idea ? And, as pid was saying, the FileUpload documentation should certainly provide some good examples. But, no matter how you do this, read this 3 times /NEVER/ accept the path or the filename that the user is entering in the form, to just write this file to disk. /read this 3 times Remember what the user has entered, and write it somewhere as a text. But create a path and a (unique) filename yourself, in your servlet, to write the file. That will protect you not only against nasty people trying to crash your server, but also against innocent users entering file names with spaces in them, or funny characters that are illegal in a filename on your system, or re-using a filename that already exists. (to name just a few of the things that can happen). All that still does not tell us why your servlet creates 0-size files, but maybe with the above explanation you can figure this out yourself. My scenario : - your first getParameter() call sucks in the whole POST (all the above) - your next getParameter() calls do not have anything else to get, and return null - by the time you try to read the body of the POST, there is nothing left, so you also get null - and then you write this (null) to the output file, and you get a null-size file. Repeat the above cycle once for each POST. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat 5.5 creates 0 byte files
Pid wrote: On 02/07/2010 14:33, Murat Birben wrote: It is a virtual machine on ESXi so df shows me the whole storage I Does it? I'm not sure it does. No, it does not. It shows only the disks allocated to this virtual machine. That's the point of virtual machines, you /can/ only access whatever is allocated to that virtual machine. think. Is there any other way to see the disk usage for virtual machines? That's a question I can't answer I'm afraid. There should be a way, from the web console of vmware ESX, to point to the one virtual machine and see how much disk space is allocated/used. But the first method is easier. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org