Re: download a file
Shing's code didn't show you what you needed? On 1/10/07, Holger Stolzenberg <[EMAIL PROTECTED]> wrote: I am very intrested! Please share your code -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von James Carman Gesendet: Mittwoch, 10. Januar 2007 02:32 An: Tapestry users Betreff: Re: download a file Let me know if Shing's example (it looks to be pretty good) isn't enough for you. The code I wrote was for a client, but there's really not much "clientness" to it, so I could probably share it. All it does is take image data out of a blob in the database and stream it back. Not rocket science by any means. The hardest part of it is the "servicey" bits. p.s. For the record, that's two phrases that I coined in the same email :-) On 1/9/07, Robert J. Walker <[EMAIL PROTECTED]> wrote: > James Carman wrote: > > > I did this by creating my own "service" in T4. > > Have some code to share? I'm sure we'd all love to see it. > > > - > 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]
Re: download a file
Let me know if Shing's example (it looks to be pretty good) isn't enough for you. The code I wrote was for a client, but there's really not much "clientness" to it, so I could probably share it. All it does is take image data out of a blob in the database and stream it back. Not rocket science by any means. The hardest part of it is the "servicey" bits. p.s. For the record, that's two phrases that I coined in the same email :-) On 1/9/07, Robert J. Walker <[EMAIL PROTECTED]> wrote: James Carman wrote: > I did this by creating my own "service" in T4. Have some code to share? I'm sure we'd all love to see it. - 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]
Re: download a file
Robert J. Walker wrote: James Carman wrote: I did this by creating my own "service" in T4. Have some code to share? I'm sure we'd all love to see it. Shing has put up this nice page that details many such things http://lombok.demon.co.uk/tapestry4Demo/app - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr Tapestry / Tacos developer Open Source / J2EE Consulting - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: download a file
James Carman wrote: > I did this by creating my own "service" in T4. Have some code to share? I'm sure we'd all love to see it. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: download a file
I did this by creating my own "service" in T4. On 1/9/07, Dennis Sinelnikov <[EMAIL PROTECTED]> wrote: Robert's Tapestry 3's method works, but Tapestry 4's method might cause some problems, at least it did when I tried it. I believe it has to do with closing the response outputstream before rewind or the rest of rendering is complete. User will be able to download the file successfully, but you'll see an error in your logs about OutputStream is already closed (or something along those lines). To get around this error, I had to implement my own download engine service, as Shing suggested. Dennis Robert J. Walker wrote: > Here's a method that will do what you're asking: > > // Tapestry 3 > protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { > HttpServletResponse response = cycle.getRequestContext().getResponse(); > response.setHeader("Content-disposition", "attachment; filename=" + filename); > response.setContentType(contentType); > response.setContentLength(content.size()); > response.getOutputStream().write(content.toByteArray()); > response.flushBuffer(); > response.getOutputStream().close(); > } > > // Tapestry 4 > protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { > WebResponse response = cycle.getInfrastructure().getResponse(); > response.setHeader("Content-disposition", "attachment; filename=" + filename); > response.setIntHeader("Content-Length", content.size()); > OutputStream stream = response.getOutputStream(new ContentType(contentType)); > stream.write(content.toByteArray()); > stream.flush(); > stream.close(); > } > > You should make sure that the filename you provide is compatible with the user's operating system, or you could run into problems. It's also advisable to make the file extension jive with the content type so that the user doesn't have to rename the file to open it. Hope this helps. > > Robert J. Walker > > > - > 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]
Re: download a file
Robert's Tapestry 3's method works, but Tapestry 4's method might cause some problems, at least it did when I tried it. I believe it has to do with closing the response outputstream before rewind or the rest of rendering is complete. User will be able to download the file successfully, but you'll see an error in your logs about OutputStream is already closed (or something along those lines). To get around this error, I had to implement my own download engine service, as Shing suggested. Dennis Robert J. Walker wrote: Here's a method that will do what you're asking: // Tapestry 3 protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { HttpServletResponse response = cycle.getRequestContext().getResponse(); response.setHeader("Content-disposition", "attachment; filename=" + filename); response.setContentType(contentType); response.setContentLength(content.size()); response.getOutputStream().write(content.toByteArray()); response.flushBuffer(); response.getOutputStream().close(); } // Tapestry 4 protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { WebResponse response = cycle.getInfrastructure().getResponse(); response.setHeader("Content-disposition", "attachment; filename=" + filename); response.setIntHeader("Content-Length", content.size()); OutputStream stream = response.getOutputStream(new ContentType(contentType)); stream.write(content.toByteArray()); stream.flush(); stream.close(); } You should make sure that the filename you provide is compatible with the user's operating system, or you could run into problems. It's also advisable to make the file extension jive with the content type so that the user doesn't have to rename the file to open it. Hope this helps. Robert J. Walker - 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]
RE: download a file
Here's a method that will do what you're asking: // Tapestry 3 protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { HttpServletResponse response = cycle.getRequestContext().getResponse(); response.setHeader("Content-disposition", "attachment; filename=" + filename); response.setContentType(contentType); response.setContentLength(content.size()); response.getOutputStream().write(content.toByteArray()); response.flushBuffer(); response.getOutputStream().close(); } // Tapestry 4 protected void download(IRequestCycle cycle, ByteArrayOutputStream content, String contentType, String filename) throws IOException { WebResponse response = cycle.getInfrastructure().getResponse(); response.setHeader("Content-disposition", "attachment; filename=" + filename); response.setIntHeader("Content-Length", content.size()); OutputStream stream = response.getOutputStream(new ContentType(contentType)); stream.write(content.toByteArray()); stream.flush(); stream.close(); } You should make sure that the filename you provide is compatible with the user's operating system, or you could run into problems. It's also advisable to make the file extension jive with the content type so that the user doesn't have to rename the file to open it. Hope this helps. Robert J. Walker - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: download a file
A custom Tapestry engine service ? Shing --- Edoardo Campagnano <[EMAIL PROTECTED]> wrote: > Hi to all, > > here's the problem: I have a file in my DB as a > byte[] array and i want a > link to permit the user to download the file. First, > I'm able to ricreate a > disk-version of the file using FileOutputStream, the > file is good (I can > open it on the server) but is generated on request > thus i can't use it as an > asset in tapestry, how can I permit the user to > obtain it? > > > > Thanks a lot, Edoardo > > > > Home page : http://uk.geocities.com/matmsh/index.html Send instant messages to your online friends http://uk.messenger.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]