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 ------------------------------------------------------------------