Question
· Nov 18, 2016

URL Link Download of Document

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?

Discussion (3)3
Log in or sign up to continue

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>

Hi!

Thanks for your code, but I tried it and can't get a file in the directory in the end. In order to get it working, I had to call the method %Save() before the %Close() one:

...
d file.CopyFrom(request.HttpResponse.Data)
d file.%Save()
w file.%Close()

I found that by this article by @Gevorg Arutiunianhttps://community.intersystems.com/post/save-file-using-nethttprequest