Written by

Article Hiroshi Sato · Aug 22, 2024 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 = $$$OKSet httprequest=##class(%Net.HttpRequest).%New()
    set httprequest.Port = 443set httprequest.Https = 1set 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
}