Popular Articles | Latest Articles | Categories | RSS Feeds

Image downloading from remote servers in ASP

Published on 5/22/2008 by Site Editor
More articles in ASP



 Vote this tutorial:

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.

Happy Coding

This part of code creates two main variables: imageUrl and strImageName.

Comments:
no comments submitted


Only members can write comments.Please, login / register to write comment.

Latest Posts

    Active News Manager - news management system




    Welcome to Dotnetindex.com:Login  |  Register
    Free software:
    Giga RSS Reader
    IkonAdman
    QMailing list
    Active News
    Download Manager (PRO)
    Download Manager (Lite)

    Search Dotnetindex.com:


    Who's online

    • There 36 online users.

    Latest tutorialsIntroduction to Dependency Injection Using StructureMap
    SEO For ASP.NET Web Site
    Using ASP.NET 3.5's ListView and DataPager Controls: The Ultimate DataPager Interface
    Using jQuery To Hijack ASP.NET MVC Form Posts
    Accessing and Updating Data in ASP.NET: Filtering Data Using a CheckBoxList
    Predictive Fetch with jQuery and the ASP.NET Ajax Library
    Building ASP.NET Web Forms to Use a MySQL Database
    A Guide to Upgrading Your XP Machine for Optimum Performance with Windows 7
    Retrieving Data from Microsoft SQL Server 2008 Using ASP.NET 3.5
    Creating an ASP.NET Dynamic Web Page Using MS SQL Server 2008 Database (GridView Display)
    Inserting Data into a Microsoft SQL 2008 Database in ASP.NET 3.5
    Using C#, ASP.NET, and ADO.NET To Develop A Multi-Tier App From Start To Finish
    URL Routing in ASP.NET 4.0
    Integrating Twitter Into An ASP.NET Website
    Creating Multiple Choice Exam Application Using ASP.NET MVC Framework
    ASP.NET Resources, Reviews

    ASP Resources, Reviews

    PHP, ASP, .NET, JSP Resources, Reviews

    Hotscripts.com Free Photoshop, Flash and 3DS MAX tutorials