Ok I think I got it now! Simply using a ResourceStreamResource instead of a ByteArrayResource, duh... I think the reason why I just couldn't see clear before is all the different obsolete examples and tutorials for older versions. The problem is, when you are new to Wicket, you are still figuring out how stuff works, and when trying to implement certain things you hit road-blocks because those code-examples don't work anymore, and you don't know why.
Here is my solution: http://pastebin.com/yQFh5gk8 This is how I'm doing it for now, returning the stream on-the-fly from the database when the ResourceLink is clicked. However, I get huge stacks of exceptions now: *java.lang.IllegalStateException: Header was already written to the resonse!* * * Here is an example, I get lots of those: http://pastebin.com/5LuDqp5a Thanks! I'm almost there I think :) 2012/8/16 Michael M <[email protected]> > I think I just made a huge step forward by overriding getData() of > ByteArrayResource. I've read that in the documentation before, but at that > time was too deep into the concept of resources that I didn't get it (I'm > completely new to Wicket). > > So, right now it works that I read my attachment, convert it into a > byte-array and deliver it, only when the link is clicked. I still get a URL > I can use for other functions (pass a .mp4-ByteArrayResource to a JW Player > instance e.g.) No creating of static resources at page-load anymore. > > Next step would be to skip the byte-array completely. How could I do my > own Resource that delivers the data as a stream, but has the same > functionality otherwise (usable in some kind of Link so that I can get the > URL)? Something like > > Resource attachmentResource = new WebResource() { >> @Override >> public IResourceStream getResourceStream() { >> // return my stream somehow >> } >> } > > > doesn't work anymore if I'm not mistaken. > > Appreciate your help so far! > > 2012/8/16 Michael M <[email protected]> > >> Hi, thanks for for quick answer! I already played around with >> ResourceStreams, but my problem was that I couldn't do the bridge from a >> Stream to a Resource with a URL. >> >> I should add, I'm not offering my ByteArrayResources as a download. I >> pass the content-type and filename, and (with the help I got from a user >> here) return it as INLINE. So, when the user clicks, the browser opens the >> filetype if it can (e.g. a picture, or a PDF with a built-in viewer). >> >> Also (and that's important) I then have a real URL which I can pass to >> Javascript functions. E.g. if the attachment is an mp3 or a video, I >> additionally use the URL of the ResourceLink to open a custom flash-player >> (JW Player).. I need a solid URL for that, for that session. >> >> When I played around I just couldn't manage to get that kind of URL when >> I worked with Streams. But I will give it another try. >> >> PS: I found this example a while ago, and wanted to implement my own >> IResourceStream to fetch the attachments from the DB, but the example is >> outdated and I couldn't figure out how to do it with a newer version of >> Wicket: http://goo.gl/imGrl >> >> >> 2012/8/16 Sven Meier <[email protected]> >> >>> Take a look at DownloadLink and FileResourceStream, and replace all File >>> related API to your CouchDB access. >>> >>> Sven >>> >>> Michael M <[email protected]> schrieb: >>> >>> >Hi, in my project I use a CouchDB with files as attachments. Currently I >>> >have a page that makes those attachments available via a ResourceLink. >>> What >>> >I do when creating that page is: >>> > >>> > - I read all attachments (I get them as an InputStream), >>> > - create a byte[] out of it, >>> > - create a static Wicket ByteArrayResource >>> > - and put the link to that resource on the page. >>> > >>> >That works for smaller files, but a huge problem is of course: it's >>> static, >>> >and I get memory problems if the attachments get too big. Also, >>> currently >>> >obviously each session does this. >>> > >>> >What I would like to do instead is: >>> > >>> > - create Resources that will load my attachments dynamically if the >>> link >>> > is clicked, >>> > - and add ResourceLinks to those resources on my page instead. >>> > - If possible, maybe deliver the attachments directly from the >>> > InputStream my CouchDB delivers, so I don't have to have any static >>> > byte-arrays on my server. >>> > >>> >That way I could make the page load immediately and deliver attachments >>> >only if required. >>> > >>> >I've wrapped my head around IResourceStreams, but I just can't see clear >>> >anymore and am confused about how to create those dynamic resources >>> (also >>> >because some old examples don't work anymore with Wicket 1.5 or 6beta3). >>> > >>> >I'd be very thankful for a short example, or a hint about how to design >>> >this. Thank you! >>> >> >> >
