Skip to main content

Image downloading from remote servers in ASP

In this tutorial, we will access to a remote server, download image, rename ths image and save to our file system. We will use one function (getImage) and one subroutine (saveImage) to complete this sampel code.

First part of our code, get image byte array from remote server. Second part contains a subroutine that writes byte array to file system.

Lets's put our function and subroutine calls in the beginning of code.

Creating variables

imageUrl = "htp://www.some-domain-name.com/images/target-image.jpg"
strImageName = "new-image.jpg"



Function and subroutine calls

saveImage getImage(imageUrl), strImageName


Here is code library:

Function getImage(strImageUrl)
' Set objHttp = CreateObject("Microsoft.XMLHTTP")
' Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
Set objHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
' Set Http = CreateObject("WinHttp.WinHttpRequest")
objHttp.Open "GET", URL, False
objHttp.Send

getImage = getImageHttp.ResponseBody
End Function

Sub saveImage(ByteArray, strImageName)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1

Set objBinaryStream = CreateObject("ADODB.Stream")
objBinaryStream.Type = adTypeBinary

objBinaryStream.Open
objBinaryStream.Write ByteArray
objBinaryStream.SaveToFile "C:\Inetpub\wwwroot\dotnetindex.com\images\" & (strImageName), adSaveCreateOverWrite
response.Write("Image has been download and saved!")
end sub


Aim of this article, to be a reference how to download bytes from remote servers. You may use this source code after adding some error controlling to sample code.

Comments

Popular posts from this blog

Web synchronization option for merge replication

http://msdn2.microsoft.com/en-us/library/ms151319.aspx SQL Server 2005 Books Online Implementing Replication over the Internet Replicating data over the Internet allows remote, disconnected users to access data when they need it using a connection to the Internet. Replicate data over the Internet using: A Virtual Private Network (VPN). For more information, see Publishing Data over the Internet Using VPN . The Web synchronization option for merge replication. For more information, see Web Synchronization for Merge Replication . All types of Microsoft SQL Server replication can replicate data over a VPN, but you should consider Web synchronization if you are using merge replication.

Request Signatures in Blackberry

Request Signatures in Blackberry need copy sigtool.db, sigtool.csk to SDK/component/Bin folder for example V 4.2.1 ../eclipse\plugins\net.rim.eide.componentpack4.2.1_4.2.1.17\components\bin