Hi Brian, Thanks for replying. I really need help here, cause this is my first time I am dealing with this.
All I wanted to know is how should and can I handle uploads of files which are then being accessed intensively. Up to now I've seen two ways to do this: (1) Store the uploaded files in the database and have a Struts Action serve those files from the DB. Pros: - The action has an ultimate control on who access what - The files are better secured Cons: - might turn up slow, even too slow to not acceptable (2) Store those uploaded files under a file system directory and have the JSP pages access these files through an Action or direct access, like any normal image, logo, etc. * Using an action - again, gaining control over the access, but might be slower then direct access. * Using direct access - probably faster (don't know how much more, though), but losing control over pages access, less secured. To do this I thought also of using Apache as the front door, using the "alias" directive + JK2 module, which I guess you are familiar with. Of course using Apache as the front door led me to the question of: "do I need it really, is it that important to have the Apache just for the files". Many people argue that using Apache is best for static files, and I guess images, photos, etc. *are* static in nature, so why not. Still I did find that the configuration is a bit awkward, however it can work. Do you use Apache for that as well? Or just Tomcat? True, first I wanted to go along and delay my decision of how to access those files and just have a file system directory. But I saw that JBoss deletes those directories upon packed deployment. In your solution I have to deploy in an unpacked manner even in production. Otherwise the whole directory will get lost. Do you see any problems with your way? It's really sad that there is not way to declare in JBoss/Tomcat a directory with characteristics similar to the alias <url-path> <dir-path> in Apache. I don't see why it is not there, am I the only one to deal with this kind of requirement? I guess not :) Regards, Erez -----Original Message----- From: Brian McSweeney [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 20, 2003 11:59 AM To: 'Struts Users Mailing List' Subject: RE: file upload problem Hi Erez, Just wondering if you figured this out. I've found what I think could be a solution. If you deploy your jboss ear in an exploded way: [ >How can a war file be deployed in a exploded way .. just create a directory named foo.ear and in the deploy directory, and unpack your EAR file in foo.ear. Then unpack the WAR file in a directory named foo.war in foo.ear. ] then you can write the uploaded files to a folder that the tomcat server will be able to serve! This works for me. Email me for more details. Brian -----Original Message----- From: Erez Efrati [mailto:[EMAIL PROTECTED] Sent: 18 August 2003 15:53 To: 'Struts Users Mailing List' Subject: RE: file upload problem I am dealing as well with the file upload issue: 1) To where should I save those files. For one I haven't done this, so this is all new. Also, I am using JBoss and I saw that no matter which directory I choose under my application context directory, this directory will be deleted and recreated upon redeployment so I guess there is a convention that I am not aware of. If I go and save my files in a "c:\files" how could links from JSP access those files. Lost in the wilderness :) How is it done? 2) I could always store those files in the database but then I would have to access them through an action, is this wise? Thanks a bunch, Erez -----Original Message----- From: Brian McSweeney [mailto:[EMAIL PROTECTED] Sent: Monday, August 18, 2003 3:46 PM To: 'Struts Users Mailing List' Subject: RE: file upload problem Shane, You are a star! That fixed it! Thanks very much, Brian -----Original Message----- From: Witbeck, Shane [mailto:[EMAIL PROTECTED] Sent: 18 August 2003 14:17 To: [EMAIL PROTECTED] Subject: RE: file upload problem I had a similar problem until I realized that you must specify a file and not a folder for the upload path (i.e. /tmp/upload/upload.txt not /tmp/upload). HTH, Shane -----Original Message----- From: Brian McSweeney [mailto:[EMAIL PROTECTED] Sent: Monday, August 18, 2003 7:24 AM To: 'Struts Users Mailing List' Subject: RE: file upload problem Thanks Prashanth, But I don't think that's the problem. Thanks anyway though, Brian -----Original Message----- From: Prashanth.S [mailto:[EMAIL PROTECTED] Sent: 18 August 2003 11:44 To: Struts Users Mailing List Subject: Re: file upload problem hi brian, try changing the folder permission from read-only??Its just a guess Thanks Prashanth Brian McSweeney <[EMAIL PROTECTED]> wrote: Hi all, I'm trying to do a file upload action based on the example struts-upload.war. I want to save the uploaded file to a folder on disk. However when I try to run the action I get an error saying I don't have access to the folder. I've tried changing the folder access and also using a different folder. I still get a file not found exception which says java.io.FileNotFoundException: .. (Access is denied) I'm using JBoss 3.2.1_tomcat4.1.24. Perhaps JBoss restricts folder access? The code that runs the struts action is:- AddProductForm frm = (AddProductForm) form; //retrieve the file representation FormFile file = frm.getTheFile(); //retrieve the file name String fileName= file.getFileName(); //retrieve the content type String contentType = file.getContentType(); //retrieve the file size String size = (file.getFileSize() + " bytes"); log.info("File details - name: "+fileName); log.info("File details - contentType: "+contentType); log.info("File details - size: "+size); // this is where I get the folder path to save the image into. String imageStorePath = Init.getImageStorePath(); log.info("the value of imageStorePath is: "+imageStorePath); try { //retrieve the file data ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream stream = file.getInputStream(); //write the file to the file specified OutputStream bos = new FileOutputStream(imageStorePath); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.close(); log.info("The file has been written to \"" + imageStorePath + "\""); //close the stream stream.close(); } catch (FileNotFoundException fnfe) { log.error("Couldn't find the file: "+ fnfe.toString()); } catch (IOException ioe) { log.error("io exception: "+ ioe.toString()); } finally{ //destroy the temporary file created file.destroy(); return mapping.findForward( WebConstants.SUCCESS ); } } Any help would be greatly appreciated. Cheers, Brian --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]