ServerXMLHTTP stream

Using ServerXMLHTTP object to show (stream or download) and image , or any other file for that matter.
It can be used to tell browser to open that image (or any other file, like pdf) or force it to download instead.
Liked the simplicity of it, and wanted to make sure I have it handy when needed.


Not Tested

Not My Work
The following steps illustrate how to use ServerXMLHTTP to stream a .jpg file to the browser. ServerXMLHTTP retrieves an XML response from an ASP page over HTTP. By using GET, the example sends a request without transferring any data to the Web server. The example writes this response to the browser's output by first informing the browser that the response is an image (image/jpg) and then passing the response directly from the Response object to display it onscreen.

    Create a new ASP page, and paste the following code in the page:
    Visual Basic Script

< % @ Language=VBScript % >
< %
Response.ContentType = "image/jpeg"
' Uncomment to prompt user for download or run with associated program.
' Response.AddHeader "content-disposition","attachment;filename=ReadMe.jpg"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")' Point to an image file with adequate access permissions granted "GET", "http://servername/picture.jpg",false
Response.BinaryWrite objHTTP.ResponseBody
Set objHTTP = Nothing
% >

Save the file to the Web server.

Browse to the file.

Views 260 Downloads 41

Classic ASP Learning Materials