Export preview as jpeg from Lua script

Hi. I’m trying to write a Lua script to export a stored instance as a jpeg file. I see that you can easily do this in png format using the /preview API and RestApiGet. I also see that you can pass the “Accept: image/jpeg” header to the same API and instead get a jpeg. However, when I try to do this, I get a timeout error.

Here’s an abbreviated version of my script:

`
function OnStoredInstance(instanceId, tags, metadata, origin)

– Generate a image preview of the DICOM file
local png = RestApiGet(‘/instances/’ … instanceId … ‘/preview’) # This works!
local headers = {
[‘Accept’]=‘image/jpeg’
}
local jpeg = HttpGet(‘http://orthanc:foobar@localhost:8042/instances/’ … instanceId … ‘/preview’, headers) # This does not!

end
`

Error:

E1014 23:29:09.853894 HttpClient.cpp:230] libCURL error: Timeout was reached
E1014 23:29:09.854102 LuaContext.cpp:258] Lua: Error in HttpGet() for URL http://orthanc:foobar@localhost:8042/instances/2512563b-c7515132-4c4fbbac-02b7697b-24a97aee/preview

Anybody have any ideas as to what I might be doing wrong?

PS - I can curl for the same URL from the command line and it works fine.

Instead of HttpGet, just use RestApiGet with a relative Url.
Once you’re in a Lua Script, the Lua engine is locked for external requests while it is not for internal request.

Thanks for the reply! But, there does not appear to be any way to set the required headers needed to preview as jpeg vs. png when using RestApiGet.

Hello,

No, this is indeed not possible with Orthanc 1.4.2.

Feel free to introduce a feature request on our issue tracker:
https://bitbucket.org/sjodogne/orthanc/issues?status=new&status=open

Sébastien-

https://bitbucket.org/sjodogne/orthanc/issues/106/unable-to-export-preview-as-jpeg-from-lua