URL Link Download of Document

Primary tabs

We have a couple of systems that send us a URL link to a PDF instead of base 64 encoding it in the HL7 message. Has anyone ever tired to take that URL, and retrieve the file off of the server to save it off somewhere?

  • 0
  • 0
  • 546
  • 1
  • 1

Answers

You can use %Net.HttpRequest to do that.

Something along these lines will work (of course you should checks for errors etc...):

USER>s request=##class(%Net.HttpRequest).%New()

USER>d request.Get("http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf")

USER>s file=##class(%FileBinaryStream).%New()

USER>d file.LinkToFile("/Users/kazamatzuri/temp/test.pdf")

USER>d file.CopyFrom(request.HttpResponse.Data)

USER>w file.%Close()
1
USER>

That was very helpful. Thanks. I just now have to add in code to check the file structure and create a new directory if it does not exist to place the PDF in.