Downloading a file from a database
In one of our STRUTS applications, I have a screen that allows users to upload and download files attached to an order. I have a JSP form that allows the user to browse a file on their machine and upload it. Also on the form is a list of the files already attached to the order, with links beside each one to either view or delete the file. When the user goes to view a file, I retrieve the file from the Oracle database and send it to a servlet that sets it's content type appropriately and then streams the file to the response writer. This works great when it is a file type that the browser can handle. For HTML, Word, Excel, JPG, etc, the browser window (Internet Explorer is our corporate standard) will render the file perfectly. However, for other file types, Explorer pops up a dialog box asking if you want to view or save the file. When the user tries to save the file, the default filename in the Save dialog is FileView.action (from the URL) instead of the filename. My question is this: Is there a way I can get the filename to come up instead? Is there a way I can accomplish this without writing temp files on the server? My initial thought was to write the temp file and generate a URL to it (someone on this list was doing that a few days back). But we don't want to be creating a bunch of files on the server and not knowing when we could clean them up, so streaming it is ideal. If it matters, we are using JBoss 3.2.2 as the app server. Thanks in advance, Robb
Re: Downloading a file from a database
Set following header to set name of attached file. response.setHeader(Content-Disposition,attachment; filename=\ + fileName + \); My two cents: Do you really want to connect to database and strean file from database. You may store temp file and check the date of temp file with database at client's request. Although, you might have to write a thread safe code which writes to temp file from database. Nicholson, Robb wrote: In one of our STRUTS applications, I have a screen that allows users to upload and download files attached to an order. I have a JSP form that allows the user to browse a file on their machine and upload it. Also on the form is a list of the files already attached to the order, with links beside each one to either view or delete the file. When the user goes to view a file, I retrieve the file from the Oracle database and send it to a servlet that sets it's content type appropriately and then streams the file to the response writer. This works great when it is a file type that the browser can handle. For HTML, Word, Excel, JPG, etc, the browser window (Internet Explorer is our corporate standard) will render the file perfectly. However, for other file types, Explorer pops up a dialog box asking if you want to view or save the file. When the user tries to save the file, the default filename in the Save dialog is FileView.action (from the URL) instead of the filename. My question is this: Is there a way I can get the filename to come up instead? Is there a way I can accomplish this without writing temp files on the server? My initial thought was to write the temp file and generate a URL to it (someone on this list was doing that a few days back). But we don't want to be creating a bunch of files on the server and not knowing when we could clean them up, so streaming it is ideal. If it matters, we are using JBoss 3.2.2 as the app server. Thanks in advance, Robb -- Thanks Manish Singla x73166 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Downloading a file from a database
As a web user I tend to have problems with these sorts of pages as I don't use IE. A lot of downloads where this sort of thing goes on often i end up with the file name of a php page rather than zip and stuff like that. My guess is is that IE is doing some of the work somewhere along the line, perhaps even windows. So I guess when you retrieve a file that IE and/or windows doesn't have provision for it doesn't do whatever it does when this seems to work. In other words it does the same thing my browser/os does. So my next guess is if you were to try wget or curl -O to request an action that does all this then you'll also get bla.action even for the file types that seem to work. Sorry that may not be that helpful, but I'd be interested whether I'm tree-barking or not. it would certainly narrow you problem down. Cheers Mark On Monday, October 27, 2003, at 10:02 PM, Nicholson, Robb wrote: In one of our STRUTS applications, I have a screen that allows users to upload and download files attached to an order. I have a JSP form that allows the user to browse a file on their machine and upload it. Also on the form is a list of the files already attached to the order, with links beside each one to either view or delete the file. When the user goes to view a file, I retrieve the file from the Oracle database and send it to a servlet that sets it's content type appropriately and then streams the file to the response writer. This works great when it is a file type that the browser can handle. For HTML, Word, Excel, JPG, etc, the browser window (Internet Explorer is our corporate standard) will render the file perfectly. However, for other file types, Explorer pops up a dialog box asking if you want to view or save the file. When the user tries to save the file, the default filename in the Save dialog is FileView.action (from the URL) instead of the filename. My question is this: Is there a way I can get the filename to come up instead? Is there a way I can accomplish this without writing temp files on the server? My initial thought was to write the temp file and generate a URL to it (someone on this list was doing that a few days back). But we don't want to be creating a bunch of files on the server and not knowing when we could clean them up, so streaming it is ideal. If it matters, we are using JBoss 3.2.2 as the app server. Thanks in advance, Robb - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Downloading a file from a database
Thanks a million, that fixed her up real good. BTW--We aren't really streaming directly from the DB, I get the file from the DB and pass it to the servlet. The servlet streams it to the response writer. So this is all in memory and goes bye-bye after I send it out to the client. -Original Message- From: Manish Singla [mailto:[EMAIL PROTECTED] Sent: Monday, October 27, 2003 5:38 PM To: Struts Users Mailing List Subject: Re: Downloading a file from a database Set following header to set name of attached file. response.setHeader(Content-Disposition,attachment; filename=\ + fileName + \); My two cents: Do you really want to connect to database and strean file from database. You may store temp file and check the date of temp file with database at client's request. Although, you might have to write a thread safe code which writes to temp file from database. Nicholson, Robb wrote: In one of our STRUTS applications, I have a screen that allows users to upload and download files attached to an order. I have a JSP form that allows the user to browse a file on their machine and upload it. Also on the form is a list of the files already attached to the order, with links beside each one to either view or delete the file. When the user goes to view a file, I retrieve the file from the Oracle database and send it to a servlet that sets it's content type appropriately and then streams the file to the response writer. This works great when it is a file type that the browser can handle. For HTML, Word, Excel, JPG, etc, the browser window (Internet Explorer is our corporate standard) will render the file perfectly. However, for other file types, Explorer pops up a dialog box asking if you want to view or save the file. When the user tries to save the file, the default filename in the Save dialog is FileView.action (from the URL) instead of the filename. My question is this: Is there a way I can get the filename to come up instead? Is there a way I can accomplish this without writing temp files on the server? My initial thought was to write the temp file and generate a URL to it (someone on this list was doing that a few days back). But we don't want to be creating a bunch of files on the server and not knowing when we could clean them up, so streaming it is ideal. If it matters, we are using JBoss 3.2.2 as the app server. Thanks in advance, Robb -- Thanks Manish Singla x73166 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]