View Single Post
Old 26th February 2020, 11:19 PM
RichardLight RichardLight is offline
Junior Member
Join Date: Nov 2011
Posts: 22
Default Server delivering binary content

We're looking to replace a set of CGI programs with equivalent .nxscript applications. One of these programs is an 'image server', which delivers a dynamically sized version of an image file.

The NexusDb web server component (at least the version we are working with - 4.5003) is currently designed only to deliver a textual response. I have managed to hack it to the point where it will deliver images, but the result isn't pretty.

Essentially I have added a socStream property to the nxllSimpleOutputCache, and changed the SaveToFile procedure so that it outputs this stream if it is instantiated, rather than outputting any text that might have been pushed to the output cache. I also needed to specify the response content type. I can set this in the script:

Server.SetVar('response-content-type', 'image/jpeg');

but I also needed to add code so that this setting is respected, and not overwritten in the ProcessRequest procedure:

if (GetVar('response-content-type') <> '') then
fReplyHeaders.Add('Content-type: '+GetVar('response-content-type'))
fReplyHeaders.Add('Content-type: '+ctype+'; charset=UTF-8');

However, if you're returning a binary response, the content type ought to reflect this without needing to be specified in your script.

Before I proceed to make larger-scale changes to the code, I thought I would check in with this group. Has anyone else attempted this, or am I on my own?