[MarkLogic Dev General] REST API call results in XDMP-UPDATEFUNCTIONFROMQUERY

Danny Sinang d.sinang at gmail.com
Wed Mar 11 12:34:03 PDT 2015


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 <d.sinang at gmail.com> 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 <d.sinang at gmail.com> 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*(*$context* *as **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*}
>> };
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150311/b465597a/attachment.html 


More information about the General mailing list