Insert binary data into HTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • multi
    New Member
    • Feb 2007
    • 8

    Insert binary data into HTML

    Hi all,
    my question is :

    is it possible to insert binary (like attachment) data into html, after that on client-side with javascript or ajax to get this data (download) from this html ?!
    give me some ideas, hints or anything :(

    Thank you !
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to The Scripts.

    I'm not sure I understand. HTML is client-side, so what do you mean by inserting binary data into HTML? Do you mean, you want to force a download when you come to a page? Do you want to use AJAX to get binary data from the server?

    Comment

    • multi
      New Member
      • Feb 2007
      • 8

      #3
      i mean, you have a html document on the client side, who contains jpeg binary data of an jpeg in base64 encoding, i have js decoder from base64 to binary (something like that) an i want to, after pressing a button or something else some event... to starts "downloadin g" this data, from the html.
      is it possible ?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I don't know if this is possible on the client-side, but you can set the Content-Disposition header using server-side code which suggests to the browser how a file should be dealt with. Inline usually displays in the browser, but if you set it to 'attachment', it suggests that the user should be asked what to do (including saving to disk). Set the mime-type to image/jpg or whatever the file.

        There is no foolproof reliable way to do this, but it should be possible by setting the correct headers.

        Comment

        • UniDyne
          New Member
          • Oct 2005
          • 18

          #5
          If I am reading your question correctly, you want to pass some sort of encoded binary information in the HTML page to be read in by a JavaScript that is included on that page.

          To do this, the binary content will need to be Base64 encoded or somesuch. Browsers get ugly when raw binary data appears in the HTML. There are plenty of places you can find a JavaScript Base64 decoder.

          You can simply place the Base64 encoded content inside a hidden DIV tag or TEXTAREA. You could also use the <![CDATA[....]]> tag to hold the encoded data for extra safety. So, what you would have is something like this:

          Code:
          <div id="mydata" style="display:none"><![CDATA[SGVsbG8gV29ybGQh]]></div>
          For a Base64 decoder, check http://rumkin.com/tools/compression/base64.php.

          Comment

          Working...