Announcement Announcement Module
Collapse
No announcement yet.
Download binary data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Download binary data

    Hey,

    I found this resource for a generic solution on how to retrieve binary data from a database to play a sound. However it's missing it's jsp counterpart.


    How can I make the binary content downloadable by the user?
    The binary content represents images, sounds and videos stored as a blob via hibernate and mysql. I would like to generate a list of links that when clicked will download the binary data it represents.
    Code:
    // Traditional way to download content
    <a href="/whatever/my_sound.mp3">sound</a>
    
    // Idea on how to download content the custom way (it is for this I need help)
    <a href=" ${model.binaryData} ">sound</a>

    Thanks in advance!

  • #2
    Well, to my understanding, displaying an image on a jsp page would seem like the logically easiest choise. It seems that setting the content type to i.e. "image/png" and the simply writing out the binary content would display the image on the page on the location where it's written.

    Naturally then, I can't logically see the semantics that makes me able to let the user download i.e. the image/sound/video. Just as I cannot see the semantics necessary to pass the sound to an embedded audio-player on the web-page, as all syntax there is to set the source of an entity is by src="" similar tags; each taking a reference/link rather than direct binary output.



    It seems that any examples on retrieving binary contents from a database only covers retrieving within a controller code as binary data.

    Any tutorials I've encountered only treats the part of retrieving binay contents from a database to a controller, as exemplified {here, here and here}, but not how to access it from a jsp page. So any help would be greatl y appreciated!

    Comment


    • #3
      +1 from me

      I am also interessted in such a solution

      I just want to have a servicemethod that reads an image from the database and then it should be accessible from the html page like this:
      Code:
      <img src="URLtoSomeServlet" .. />
      can anyone point me to:
      • some examples
      • a third partylib
      • or any other resource?

      do I have to implement some caching/servlet by myself?

      Comment


      • #4
        Stream the content to the user.

        1) set the correct response type (image/jpeg or whatever image type it is)
        2) stream the blob to the user (response.write)

        that is it.

        That goes for all the files, what the client does with it is out of your control! So if a user has a default action to play mp3 files in an embedded player it will be done. If the user should be asked what to do, that is what is happening.

        So you can only stream the resource and let the user decide what to do with it (http is all about resources remember!).

        I found this resource for a generic solution on how to retrieve binary data from a database to play a sound. However it's missing it's jsp counterpart.
        It isn't missing its JSP counterpart IT IS what you need to do, no more no less. Simply create a controller, map it to *.wav, *.mp3, implement the logic in your controller to retrieve the desired resource from where ever you want. And let it stream.

        Comment


        • #5
          From what I've learned since this post started is that it can be done.. This is how in rough steps:

          In the document where you want to retrieve the binary data:
          Code:
              <a href="getBinaryFile.html">download binary data</a>
          The html page "getBinaryFile.html" needs to be mapped to a controller which returns another page. The controller should fetch the binary stream from either database or file, then simply write the outputstream until there's no more data. Keep in mind though that the contenttype needs to be set by the HttpServletRequest and that response cannot contain anything else than the binary data.

          Here's a resource which should help you get started.

          Hope this helps



          EDIT: Ok, your response was faster
          Last edited by Toxic; Aug 5th, 2008, 09:02 AM.

          Comment


          • #6
            tx

            man that was sooo easy in SEAM:
            just use a tag and set the value to the db field:
            Code:
            <s:graphicImage value="#{auction.image.data}" ../>

            Comment

            Working...
            X