Skip to main content

rest.downloadFile

rest.downloadFile(url, id, filename)

Description

Downloads a file through HTTP to disk. Uses USER and PASSWORD parameters if present. Uses headers defined.

Returns an attachment object with path to the file downloaded in disk.

Parameters

ParameterTypeExplanation
urlStringThe endpoint to call to download the file
idStringThe id of the ticket. Used to generate the folder name where to download the file
filenameStringThe name of the file

Example

// A text file: https://www.w3.org/TR/PNG/iso_8859-1.txt
// A PDF file: https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
url = "https://www.w3.org/2008/site/images/logo-w3c-mobile-lg"

http = option.rest
http.rest.addParam("endpoint","HTTP")

attachment = http.downloadFile(url, "1", "logo-w3c-mobile-lg.png")


println attachment.getFilename()
println attachment.getBase64()

msg = api.newMessage("HelloMessageType")
msg.put("text", "Hello world")
msg.put("attachments/0", attachment)
api.publish(msg)