[MarkLogic Dev General] Image stored in marklogic server - display it from JSP

liza liza at ifactory.com
Fri May 18 10:50:08 PDT 2007


We store our binary data in MarkLogic but use XQuery only to return a 
byte stream of the object.  From that point a Java servlet handles 
returning the stream to the browser.  One advantage of that architecture 
is that the servlet context will already know the correct MIME type for 
a given file extension, so we don't need to hand-code whether we're 
returning image/jpeg or audio/mpeg.

As for your second question, I don't know if it's possible to define a 
function inside your JSP but I doubt you would want to. Architecturally 
it would be better to store library functions in a centralized place 
(either on the filesystem or in the database) where they can be used by 
multiple pages.

Hope this is helpful.

--Liza

--
Liza Daly
Senior Software Engineer
iFactory <http://www.ifactory.com>

Saptarshi Newyork wrote:
> Hi,
> My first question is regarding display an image from JSP when the 
> image is stored in Marklogic server.
>  
> I have tried 2 things in the JSP as listed below:
>  
> *1. (No Result - Red cross mark in place of the image. Server could 
> not execute the xqy file)*
>  
> <image width="400" height="300"
> src="get-img-jpeg.xqy?uri={fn:base-uri(doc("c:/100_2754.JPG")))"/>
>  
> Here I have tried to call a XQY file with the input of the uri of the 
> image. The XQY file has the code like the following:
>  
> module "http://www.w3.org/2003/05/xpath-functions"
> let $uri := xdmp:get-request-field("uri")
> return (xdmp:set-response-content-type("image/jpeg"), doc($uri))
>  
> It does not show me the image. I want to know
>       i)  How can I call an xqy file from a JSP?
>       ii) Can I define XQY functions inside a JSP? What will be the 
> syntax?
>  
> *2. (return nothing)*
>  
> <xq:execute >
>    <xq:query>
>        let $uri := fn:base-uri(doc("100_2754.JPG"))
>        return (xdmp:set-response-content-type("image/jpeg"), doc($uri))
>   </xq:query>
> </xq:execute>
>  
>  
> */I don't want to store the images in the file system and want to 
> store them in marklogic. Please tell what shall be the right way to 
> solve this problem./*
> */ /*
> */Please also let me know if it is possible to define xquery function 
> in the JSP and call XQY from JSp?/*
> *//* 
> */Thanks in advance,/*
> */Regards,/*
> */Saptarshi/*
>
> ------------------------------------------------------------------------
> It's here! Your new message!
> Get new email alerts 
> <http://us.rd.yahoo.com/evt=49938/*http://tools.search.yahoo.com/toolbar/features/mail/> 
> with the free Yahoo! Toolbar. 
> <http://us.rd.yahoo.com/evt=49938/*http://tools.search.yahoo.com/toolbar/features/mail/> 
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
>   



More information about the General mailing list