[MarkLogic Dev General] Retrieving file name/document URI of binary content
Amar Wakkar
amar_wakkar at hotmail.com
Mon Nov 14 12:30:20 PST 2011
for $x in collection("imageCollection")return( xdmp:node-uri($x) , $x )
returns empty output, no error while executing.:
your query returned an empty sequence
From: Danny.Sokolsky at marklogic.com
To: general at developer.marklogic.com
Date: Mon, 14 Nov 2011 12:22:49 -0800
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content
You might try using the xdmp:node-uri function instead of document-uri. -Danny From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Amar Wakkar
Sent: Monday, November 14, 2011 12:20 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content Hello David, It seems the query can not run if there are binary elements in collection. I get following error when I run the query in QConsole: XDMP-CHILDNODEKIND: $i/node() -- element nodes cannot have binary node children
ThanksAmaresh WakkarFrom: dlee at epocrates.com
To: general at developer.marklogic.com
Date: Mon, 14 Nov 2011 19:58:07 +0000
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary contentYou can return them as pairs in a sequence for $x in collection("user10")return( fn:document-uri($x) , $x ) Not sure why the XCC code isnt returning the document-uri but it might not know it ) ----------------------------------------David A. LeeSenior Principal Software EngineerEpocrates, Inc.dlee at epocrates.com812-482-5224 From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Amar Wakkar
Sent: Monday, November 14, 2011 2:42 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content Hello David, No luck, I am getting following error when I try your suggestion: com.marklogic.xcc.exceptions.XQueryException: XDMP-TOOFEWARGS: (err:XPST0017) fn:document-uri() -- Too few args, expected 1 but got 0 [Session: user=user, cb=XCCTestDB [ContentSource: user=user, cb=XCCTestDB [provider: address=localhost/127.0.0.1:8006, pool=1/64]]] [Client: XCC/4.2-7, Server: XDBC/5.0-1]in /eval, on line 1expr: fn:document-uri() at com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse(ServerExceptionHandler.java:30) at com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(EvalRequestController.java:78) at com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(AbstractRequestController.java:78) at com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:268) Basically I want to be able to get images stored in Marklogic server back on a JSP page in an <img> tag. So far, I can get the html content upto the JSP page, however to render image, I want to be able to use the same name used while storing the image in Marklogic database e.g. image1,2,3 etc as document URI. I tried following in QConsole which works but there are two problems with it: for $x in collection("user10")returnfn:document-uri($x) Problem:1 : It retrieves only the file names so I will have to write one query to get the content and other query to get the file names, that does not sound quite right. Problem:2:Even if problem-1 is not an issue, how do I get it to work from Java code? Should I copy these lines in a .xqy module/page and invoke it somehow from JSP? Is there any better way to get image and it's document-uri in one go from Marklogic. I stored them as binary instances when creating content. I am using Marklogic-5. ThanksAmaresh Wakkar From: dlee at epocrates.com
To: general at developer.marklogic.com
Date: Mon, 14 Nov 2011 15:08:19 +0000
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary contentTry this: Request request = session.newAdhocQuery(" collection('imageCollection')/document-uri() "); ----------------------------------------David A. LeeSenior Principal Software EngineerEpocrates, Inc.dlee at epocrates.com812-482-5224 From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Amar Wakkar
Sent: Monday, November 14, 2011 9:27 AM
To: general at developer.marklogic.com
Subject: [MarkLogic Dev General] Retrieving file name/document URI of binary content Dear all, I am learning ways of doing things in Marklogic server. I have managed to save a collection to Marklogic server which consists of few .gif images. The document URI's are the actual file names when I stored them in collection e.g. image1, image2 etc..The collection is named "imageCollection". I can query for "imageCollection" and it does return 3 images in result set. Unfortunately, I am unable to figure out how to get "file name" or Document URI of these images ? createOptions = ContentCreateOptions.newBinaryInstance(); createOptions.setCollections(new String[]{"imageCollection"}); createOptions.setFormatBinary(); content = ContentFactory.newContent(someContent.getAttachmentsFileNames()[i], someContent.getAttachments()[i], createOptions); System.out.println("Inserting contents.."); session.insertContent(content); The call to Request request = session.newAdhocQuery(" collection(\"imageCollection\") "); ResultSequence rs = session.submitRequest(request); while(rs.hasNext()){ System.out.println("Inside contentDao 44444444"); ResultItem item = rs.next(); Following call returns null System.out.println(item.getDocumentURI()); Please help me understand how to get the file names of the images so that I can use them to render back on screen. ThanksAmaresh Wakkar
_______________________________________________ General mailing list General at developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General at developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20111114/dc281e63/attachment-0001.html
More information about the General
mailing list