Stream binary data to a website

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:52 pm

by Stephen >> Tue, 7 Dec 2004 3:44:25 GMT

Hi,
Is there a way yet to be able to set the content type of a web session reply? I am wanting to return a binary file that is stored within our database without having to write the file to the webserver, then link to that file to download it.
The same issue was raised over a year ago in the Tech_General newsgroup, so I was wondering if there has been a solution found yet.

Everything I have seen about it makes it look conceptually very simple. Just set the content type in the http header, then return the binary. So is there a way to manipulate the headers within Jade before sending a response?

Thanks
Stephen

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by allistar >> Tue, 7 Dec 2004 10:06:10 GMT

Hi Stephen,
Sorry if I appear to be pushing my own barrow, but JHP allows you to do this easily. Using JHP (think PHP but for JADE) you can easily set the content type of the returned data. This allows you to echo out any binary from the database, such as a jpeg, gif, pdf, zip etc. As long as the mime type is set to an appropriate value the browser will see the data as an image, document, zip archive - whatever you like. The advanteg of this is that you don't have the security risk of copying a file to the web servers file system and then providing a link to the file. The other problem with that approach is that you don't necessarily know when to remove the temporary file.

Using JHP you could do something like this:

<?jhp
vars
file: File;begin

create file transient;
file.fileName := "c:\temp\someimage.jpg";
file.kind := file.Kind_Binary;
echo(file.readBinary(file.fileLength()).String);
addHTTPHeader("Content-type", "image/jpeg");
end;
?>

That example has the JHP block of code (which is just JADE code) read from a file and echo the contents to a browser. Probably not a very good example - you would more likely get the binary straight from an object in the database, but it highlights how it could easily be done.

In the case of returning binary data you don't want to have standard tags like <html> and <body> as they are part of the dta stream and the jpeg sent would no longer be valid. When displaying plain HTML you can treat JHP like PHP, in that you embed JADE code into an html page, and that code would then get executed on the JADE server, returned to the web server, and then to the browser.

Regards,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by Stephen >> Tue, 7 Dec 2004 20:20:00 GMT

I did notice that your JHP product could do it. I would rather not have to purchase another product though just for one page in our system that needs to be able to do this.

I am quite surprised that it is not built into Jade somewhere, surely this would be quite a common requirement, obviously not I guess.

What does JHP cost anyway? You can reply directly to me stephen@tenderlink.com if you would rather not post your prices.

Thanks Alistar,

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by allistar >> Tue, 7 Dec 2004 21:13:20 GMT

Hi Steve,
The price is on the Silvermoon website for the world to see:

http://www.silvermoon.co.nz/jhp.html

$1995 NZD per JADE database it will be used on. Unlimited users, no additional costs or ongoing maintenance fees. You do need to make sure you have an adequate JADE license (the JHP worker threads will consume a JADE CP "Concurrant Process" count). Note that for the needs of a large client I have modified JHP to allow it to be fairly easily slotted in instead of jadhttp.dll so a jadhttp.dll web site can have the backend replaced by JHP. This gives web developers the flexibility of PHP with jadhttp.dll templates/tags still functioning.

Have you tried making JADE output a "Content-type: image/jpeg;" directive as the very first thing it outputs? From memory (and this was from a very old version of the JADE internet enabling technology) you could echo additional HTTP header fields like that and as long as the body of the page (or in this case image) starts after a blank line then the jadhttp.dll module will treat the header directives properly. I may be wrong though. Surely there is some way of adding HTTP headers to the data that is returned?

Regards,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by Ray >> Thu, 9 Dec 2004 21:22:43 GMT

Allistar, can I just commend you for such an incredible innovation? JHP is definitely one of those features that I have wished JADE supported natively. I'm very impressed.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by allistar >> Thu, 9 Dec 2004 21:53:30 GMT

Hi Ray,
Thanks. I saw a gap and needed it filled, so I filled it. JADE is very open, so creating JHP was technically easy, even if it took quite a while.

Thanks,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Stream binary data to a website

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:53 pm

by rob >> Thu, 16 Dec 2004 4:04:49 GMT

Jade certainly did support this, and I used it for the purpose you describe. I believe the Jade web client may use the feature itself. However I recall it was rather crude ... you had raw access to set the http header data to whatever you like, so care was required ... perhaps for this reason it wasn't documented too prominently. Unfortunately, I've been through my archives and been unable to find any details of how to do it! Sorry ... Rob


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 25 guests