[MarkLogic Dev General] Retrieving file name/document URI of binary content
Frank Sanders
Frank.Sanders at marklogic.com
Mon Nov 14 13:44:04 PST 2011
How are you executing the query? If you're running this through CQ or Query Console as XML the error may be caused by how the results are returned.
Try executing the module directly from an application server, or as a return format other than XML.
-fs
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Amar Wakkar
Sent: Monday, November 14, 2011 4:28 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content
Hello David,
I tried but no joy...still giving same error about binary nodes not being allowed in element node.
for $uri in collection("user10")/document-uri(.)
return ( $uri , doc($uri) )
Interestingly, when I created a collection of just text and xml contents both of your suggestions work so the issue is definitely with the binary data and the way it is queried/represented in Marklogic.
It may sound a silly question, but when I stored a binary image in Marklogic collection along with a document-uri then should there not be some way e.g. Metadata about the resultset which should tell me what is the associated URI for this content when it was stored in Marklogic? It just happened to be a binary image file but should that matter as far as retrieving a document-uri is concerned? It is just a name used to store the data in database, if I can retrieve that name for an XML or TXT file then why not for Binary image?
Thanks
Amaresh Wakkar
________________________________
From: dlee at epocrates.com
To: general at developer.marklogic.com
Date: Mon, 14 Nov 2011 21:09:36 +0000
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content
I still dont understand why this doesnt work:
for $x in collection("user10")
return
( fn:document-uri($x) , $x )
But you can always try
for $uri in collection("user10")/document-uri(.)
return ( $uri , doc($uri) )
----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
dlee at epocrates.com<mailto:dlee at epocrates.com>
812-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 3:53 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content
Thanks!!!
The dot definitely made the difference.. I can now query the content and document-uri in separate queries, but it would have been great if I could just fetch them together in single query like other experts pointed out:
More importantly, if I query these two separately, is there a guarantee that they will come in correct order everytime? I mean the image name at position 1 will always correspond to image-1 retrieved in a separate query for that collection?
If it all was fetched in single query then these issues would not have come, is it not?
Of course there is one way to do it i.e. a nested query. Get the file names/document-uris and then get the documents but that will be more than 2 calls to Marklogic, I think.
Thanks
Amaresh
________________________________
From: semerau at hotmail.com
To: general at developer.marklogic.com
Date: Mon, 14 Nov 2011 12:58:41 -0700
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of binary content
Try this:
Request request = session.newAdhocQuery(" collection('imageCollection')/document-uri(.) ");
notice the dot in the document-uri() function
________________________________
From: 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 content
You 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. Lee
Senior Principal Software Engineer
Epocrates, Inc.
dlee at epocrates.com<mailto:dlee at epocrates.com>
812-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 [prov
ider: address=localhost/127.0.0.1:8006, pool=1/64]]]
[Client: XCC/4.2-7, Server: XDBC/5.0-1]
in /eval, on line 1
expr: fn:document-uri()
at com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse
(ServerExceptionHandler.java:30)
at com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(Ev
alRequestController.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")
return
fn: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.
Thanks
Amaresh 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 content
Try this:
Request request = session.newAdhocQuery(" collection('imageCollection')/document-uri() ");
----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
dlee at epocrates.com<mailto:dlee at epocrates.com>
812-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.
Thanks
Amaresh Wakkar
_______________________________________________ General mailing list General at developer.marklogic.com<mailto:General at developer.marklogic.com> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General at developer.marklogic.com<mailto:General at developer.marklogic.com> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General at developer.marklogic.com<mailto:General at developer.marklogic.com> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list General at developer.marklogic.com<mailto: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/45eaf843/attachment-0001.html
More information about the General
mailing list