[BitBucket user: Amos Onn] [BitBucket date: 2017-12-05.17:56:07] When attempting to access the preview of an Instance via the REST-API in a lua script, we only receive the null-terminated portion of the png (usually not much more than the magic value).
[BitBucket user: Sébastien Jodogne] [BitBucket date: 2017-12-14.16:45:17] Please could you provide a sample Lua script in order for us to be sure to work on your precise issue?
[BitBucket user: Amos Onn] [BitBucket date: 2018-01-04.15:11:38] ``` function OnStoredInstance(instanceId, tags, metadata) local preview = RestApiGet('/instances/' .. instanceId .. '/preview') local headers = { ["content-type"]="Image/PNG", } HttpPost("http://172.20.5.1:1235", preview, headers) Delete(SendToModality(instanceId, 'server')) end ``` This sent a POST request to the server, but only with the first 8 bytes which are the signature of a PNG file. I looked through the LUA scripting part of the Orthanc source for `RestApiGet`, and it seems to be using the correct method of the LUA C-API (namely, the one that passes a buffer by size and not by null termination). I'm pretty sure I've attempted printing the output the received object and it looked the same; but now that I think of it, perhaps the log function used the null terminator, and `HttpPost` uses it as well?
[BitBucket user: Sébastien Jodogne] [BitBucket date: 2018-07-12.13:54:10] For reference, here is a sample [Flask](http://flask.pocoo.org/) script to mimic the behavior of Amos' HTTP server running on `http://172.20.5.1:1235`: ``` from flask import Flask from flask import request app = Flask(__name__) @app.route('/', methods = [ 'POST' ]) def store(): with open('/tmp/preview.png', 'wb') as f: f.write(request.get_data()) return 'ok' if __name__ == "__main__": app.run(debug = True, host = '0.0.0.0') ``` This Flask script writes all the HTTP POST requests it receives into file `/tmp/preview.png`. And here is the corresponding Lua script in Orthanc (the Flask script runs by default on `http://localhost:5000/`): ``` function OnStoredInstance(instanceId, tags, metadata) local preview = RestApiGet('/instances/' .. instanceId .. '/preview') local headers = { ['content-type'] = 'image/png', } HttpPost('http://localhost:5000', preview, headers) Delete(instanceId) end ```
[BitBucket user: Sébastien Jodogne] [BitBucket date: 2018-07-12.13:54:43] fix issue #77 → https://hg.orthanc-server.com/orthanc/changeset/c8d369400ae1