This works just fine for me on ML5:

let$d := 
xdmp:document-get("http://www.gotdogsonline.com/chinese-foo-dog-pictures-breeders-puppies-rescue/pictures-photos/chinese-foo-dog-0001.jpg";)
return
xdmp:document-insert("/foo.jpg",$d);
for $i in collection()
return ($i/document-uri(.),$i)

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Monday, November 14, 2011 4:28 PM
To: [email protected]
Subject: General Digest, Vol 89, Issue 53

Send General mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://developer.marklogic.com/mailman/listinfo/general
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of General digest..."


Today's Topics:

   1. Re: Retrieving file name/document URI of binary content
      (Amar Wakkar)


----------------------------------------------------------------------

Message: 1
Date: Mon, 14 Nov 2011 21:27:39 +0000
From: Amar Wakkar <[email protected]>
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI
        of binary content
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


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?
ThanksAmaresh Wakkar
From: [email protected]
To: [email protected]
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.
[email protected]
812-482-5224

 


From: [email protected] 
[mailto:[email protected]]
On Behalf Of Amar Wakkar

Sent: Monday, November 14, 2011 3:53 PM

To: [email protected]

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: [email protected]

To: [email protected]

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: [email protected]

To: [email protected]

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.
[email protected]
812-482-5224

 


From: [email protected] 
[mailto:[email protected]]
On Behalf Of Amar Wakkar

Sent: Monday, November 14, 2011 2:42 PM

To: [email protected]

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: [email protected]

To: [email protected]

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.
[email protected]
812-482-5224

 


From: [email protected] 
[mailto:[email protected]]
On Behalf Of Amar Wakkar

Sent: Monday, November 14, 2011 9:27 AM

To: [email protected]

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 
[email protected] 
http://developer.marklogic.com/mailman/listinfo/general






_______________________________________________ General mailing list 
[email protected] 
http://developer.marklogic.com/mailman/listinfo/general




_______________________________________________ General mailing list 
[email protected] 
http://developer.marklogic.com/mailman/listinfo/general






_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general                         
                  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://developer.marklogic.com/pipermail/general/attachments/20111114/b2bc2223/attachment.html
 

------------------------------

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general


End of General Digest, Vol 89, Issue 53
***************************************
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to