What type is the return of HttpPost?

I’m using this code to get the dicom file :

local dicom = RestApiGet(“/instances/” … instanceId … “/file”)

What exactly is dicom in this case? A string?

I can write the dicom file to some other location, with this code :

– Write to the file
local target = assert(io.open(path … “/” … instanceId … “.dcm”, “wb”))
target:write(dicom)
target:close()

I can send the dicom to some express api, when I just send the dicom, like :

local answer = HttpPost(url, dicom, headers)

BUT, it seems that I can’t wrap the dicom object into a more complex string/object, this code doesn’t work :

local query =
‘{ “query”: “mutation ($file: Upload!, $tags: [String!]) { upload(file: $file, tags: $tags) { uuid filename status datasets { uuid uri layers { name shape } } } }”, “variables”: { “file”: null, “tags”: [“auto-sync”] } }’
local payload = {
[“operations”] = query,
[“map”] = ‘{ “0”: [“variables.file”] }’,
[“0”] = dicom
}

PrintRecursive(payload)

local answer = HttpPost(graphqlURL, DumpJson(payload, true), headers)

In general, I can’t print the content of dicom…

Is is possible to get the 3 snippet working?

Thanks

Hello,

Regarding the first part of your question, the result of “HttpPost()” is a binary string in Lua:
https://www.lua.org/pil/2.4.html

Regarding the second part of your question, “the JSON format natively doesn’t support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash escapes) in JSON. An obvious method to escape binary data is to use Base64.”
https://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64

HTH,
Sébastien-

Thanks for the quick reply and the clarifications about the binary string.

Unfortunately, I can’t modify the server I’m sending the dicom to, so if I encode the dicom into base64, it will not decode it… Is it possible to do multipart/form-data with the HttpPost?

Yes, this should be possible in Lua. Give a try.