Article
· Aug 22 1m read

How to download an image file from a web server using ObjectScript language

InterSystems FAQ rubric

The following code downloads https://www.intersystems.com/assets/intersystems-logo.png and saves the file as c:\temp\test.png.

You need to define an SSL configuration called SSLTEST before executing this code

 

ClassMethod download() As %Status
{
    Set sc = $$$OK
    Set httprequest=##class(%Net.HttpRequest).%New()
    set httprequest.Port = 443
    set httprequest.Https = 1
    set httprequest.SSLConfiguration = "SSLTEST"
    Set httprequest.Server="www.intersystems.com"
    Do httprequest.Get("/assets/intersystems-logo.png")
    Set httpresponse=httprequest.HttpResponse
    Set file=##class(%File).%New("c:\temp\test.png")
    Do file.Open("NWUK\BIN\")
    Do file.CopyFrom(httpresponse.Data)
    Do file.Close()
    Return sc
}
Discussion (0)1
Log in or sign up to continue