Hi Geert, I did try calling the said URL via PUT and POST but got the same XDMP-UPDATEFUNCTIONFROMQUERY error.
Was I supposed to configure something somewhere to tell ML this was supposed to be called via PUT or POST ? Regards, Danny Sent from my iPhone > On Mar 12, 2015, at 4:27 AM, Geert Josten <[email protected]> wrote: > > Hi Danny, > > Jumping in late on this thread, but wanted to remark that you might not need > to go through al this if you switched from doing GET’s to this endpoint to > using POST or PUT.. > > Cheers > > From: Danny Sinang <[email protected]> > Reply-To: MarkLogic Developer Discussion <[email protected]> > Date: Thursday, March 12, 2015 at 4:03 AM > To: MarkLogic Developer Discussion <[email protected]> > Subject: Re: [MarkLogic Dev General] REST API call results in > XDMP-UPDATEFUNCTIONFROMQUERY > > Thanks Joe. > > I decided to not use xdmp:spawn anymore. > > Here's the working code : > > ========================================================== > xquery version "1.0-ml"; > > module namespace local = "http://marklogic.com/rest-api/resource/resize"; > > declare namespace rapi = "http://marklogic.com/rest-api"; > > declare %rapi:transaction-mode("update")function local:get($contextas > map:map, $params as map:map) as document-node()* { > let $image_server_root := "http://solrdev1.mycompany.com:7000/resize_image" > > let $uri := map:get($params,"uri") > let $width := map:get($params,"width") > let $height := map:get($params,"height") > let $resized_uri := > fn:concat(fn:substring-before($uri,".jpg"),"_",$width,"_",$height,".jpg") > > let $resized_image := > if (xdmp:uri-is-file($resized_uri)) then > fn:doc($resized_uri) > else > let $image := fn:doc($uri)/node() > let$image_name := fn:tokenize($uri,"/")[last()] > > let$temp_image := > xdmp:http-put(fn:concat($image_server_root,"/",$width,"/",$height,"/",$image_name,"?resized_uri=",$resized_uri), > (), $image)[2] > let$_ := xdmp:document-insert("/2014/11/20/danny.jpg", $temp_image, > xdmp:default-permissions()) > return > $temp_image > > let $mime_type := map:put($context,"output-types","image/jpeg") > return document{$resized_image} > }; > > >> On Wed, Mar 11, 2015 at 8:57 PM, Joe Bryan <[email protected]> wrote: >> Hi Danny, >> >> You don't have to make the entire transaction a query to spawn an update; >> you can explicitly set the transaction-mode in the xdmp:spawn-function >> expression. (note: you will have to explicitly commit the update transaction) >> >> Ex: >> >> xdmp:spawn-function(function() { >> xdmp:document-insert("/2014/11/20/danny.jpg", $temp_image, >> xdmp:default-permissions()), >> xdmp:commit() >> }, >> <options xmlns="xdmp:eval"> >> <transaction-mode>update</transaction-mode> >> </options>) >> >> Thanks. >> >> -jb >> >> From: Danny Sinang <[email protected]> >> Reply-To: MarkLogic Developer Discussion <[email protected]> >> Date: Wednesday, March 11, 2015 at 2:34 PM >> To: general <[email protected]> >> Subject: Re: [MarkLogic Dev General] REST API call results in >> XDMP-UPDATEFUNCTIONFROMQUERY >> >> I think it's working now. >> >> Just added this line : >> declare namespace rapi="http://marklogic.com/rest-api"; >> >> >>> On Wed, Mar 11, 2015 at 3:27 PM, Danny Sinang <[email protected]> wrote: >>> I tried prefixing my function declaration like this : >>> >>> declare %rapi:transaction-mode("update") >>> >>> as suggested in >>> http://docs.marklogic.com/guide/rest-dev/extensions#id_17130 . >>> >>> But I'm now getting this error : >>> >>> XDMP-UNBPRFX: (err:XPST0081) Prefix rapi has no namespace binding. >>> >>> Regards, >>> Danny >>> >>> >>>> On Wed, Mar 11, 2015 at 3:00 PM, Danny Sinang <[email protected]> wrote: >>>> Hello, >>>> >>>> Whenever I make call to >>>> >>>> http://marklogic.mycompany.com:9042/v1/resources/resize?rs:width=300&rs:height=300&rs:uri=/2014/11/20/IC20141120.jpg >>>> >>>> I get this error message : >>>> >>>> <rapi:error xmlns:rapi="http://marklogic.com/rest-api"> >>>> <rapi:status-code>500</rapi:status-code> >>>> <rapi:status>INTERNAL ERROR</rapi:status> >>>> <rapi:message-code>XDMP-UPDATEFUNCTIONFROMQUERY</rapi:message-code> >>>> <rapi:message> >>>> XDMP-UPDATEFUNCTIONFROMQUERY: >>>> Q{http://marklogic.com/rest-api/resource/resize}get#2($context, >>>> $service-params) -- Cannot apply an update function from a query. See the >>>> MarkLogic server error log for further detail. >>>> </rapi:message> >>>> </rapi:error> >>>> >>>> I know this happens because of the xdmp:document-insert() call inside the >>>> code for that API call. >>>> >>>> My question is, is there a workaround for this ? >>>> >>>> I already tried wrapping the document-insert call with >>>> xdmp:spawn-function, but that didn't work either. >>>> >>>> Below is the code. >>>> >>>> Regards, >>>> Danny >>>> >>>> ======================================================================================= >>>> xquery version "1.0-ml"; >>>> >>>> module namespace local = "http://marklogic.com/rest-api/resource/resize"; >>>> >>>> declare option xdmp:update "true"; >>>> >>>> declare function local:get($contextas map:map, $params as map:map) as >>>> document-node()* { >>>> let $image_server_root := >>>> "http://solrdev1.mycompany.com:7000/resize_image" >>>> let $uri := map:get($params,"uri") >>>> let $width := map:get($params,"width") >>>> let $height := map:get($params,"height") >>>> let $resized_uri := >>>> fn:concat(fn:substring-before($uri,".jpg"),"_",$width,"_",$height,".jpg") >>>> >>>> let $resized_image := >>>> if (xdmp:uri-is-file($resized_uri)) then >>>> >>>> fn:doc($resized_uri) >>>> else >>>> let $image := fn:doc($uri)/node() >>>> >>>> let$image_name := fn:tokenize($uri,"/")[last()] >>>> >>>> let$temp_image := >>>> xdmp:http-put(fn:concat($image_server_root,"/",$width,"/",$height,"/",$image_name,"?resized_uri=",$resized_uri), >>>> (), $image)[2] >>>> let$_ := xdmp:spawn-function(function() { >>>> xdmp:document-insert("/2014/11/20/danny.jpg", $temp_image, >>>> xdmp:default-permissions()) }) >>>> return >>>> $temp_image >>>> >>>> let $mime_type := map:put($context,"output-types","image/jpeg") >>>> return document{$resized_image} >>>> }; >>>> >> >> >> _______________________________________________ >> 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
