How to save byte stream as binary document

Discussion in 'ASP General' started by eengel@gmail.com, Apr 2, 2007.

  1. Guest

    Hi,

    A site Im working with has an API that allows one to retrieve files.
    The file is a Word doc sent as a byte stream.

    url="blah.asp?fileid=777777"
    set oXMLHTTP=server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    oXMLHTTP.open "POST",url,false
    oXMLHTTP.send
    binData=oXMLHTTP.responseText

    I am trying to save the stream as a file on the Web server. It isn't
    working. I've tried using FS.OpenTextFile, Stream.Write, etc.
    Nothing is working.

    Anyone have any sample code on how to do this?
    Thanks
     
    , Apr 2, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    >
    > A site Im working with has an API that allows one to retrieve files.
    > The file is a Word doc sent as a byte stream.
    >
    > url="blah.asp?fileid=777777"
    > set oXMLHTTP=server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    > oXMLHTTP.open "POST",url,false
    > oXMLHTTP.send
    > binData=oXMLHTTP.responseText
    >
    > I am trying to save the stream as a file on the Web server. It isn't
    > working. I've tried using FS.OpenTextFile, Stream.Write, etc.
    > Nothing is working.
    >
    > Anyone have any sample code on how to do this?
    > Thanks
    >


    Dim oWinHTTP
    Dim oStream

    Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

    oWinHTTP.Open "GET", "blah.asp?fileid=777777", False
    oWinHTTP.Send

    If oWinHTTP.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write oWinHTTP.responseBody
    oStream.SaveToFile "c:\temp\blah777777.doc"
    oStream.Close
    End If

    BTW, Are you sure you need a POST ? Your not sending any data in the send
    then GET would be more appropriate.
     
    Anthony Jones, Apr 3, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    10,998
    John Harrison
    Jul 26, 2004
  2. Replies:
    20
    Views:
    9,951
    licebmi
    Sep 7, 2009
  3. Deep
    Replies:
    6
    Views:
    526
    Nick Keighley
    Feb 28, 2007
  4. dolphin
    Replies:
    6
    Views:
    596
    Thomas Fritsch
    Mar 18, 2007
  5. Roedy Green

    byte stream vs char stream buffer

    Roedy Green, May 7, 2014, in forum: Java
    Replies:
    20
    Views:
    269
    Silvio
    May 18, 2014
Loading...

Share This Page