Reputation: 1179
I would like to create a custom endpoint to upload files, can I use the generic Rest API stubs and use the POST method to get the file content.. I see in the documentation
In MarkLogic 8, POST methods in a single-statement transaction are executed in query mode
what does that mean ? can I just do the following,
declare function repo:post($context as map:map, $params as map:map,$input as document-node()*) as document-node()*
{
let $filename := xdmp:get-request-field-filename("upload")
let $contentType := xdmp:get-request-field-content-type("upload")
......
};
will this take "multipart/form-data;" ?? Are there any examples that I can look ? The above way does not seem to be working for me
I also tried (and love the annotations) using RXQ (https://github.com/xquery/rxq), but fails for multipart/form-data ..
Any pointers on how to approach will be really helpful..
Thanks, Ravi
Upvotes: 3
Views: 427
Reputation: 7335
If you just want to write a single document, consider using the built-in REST endpoint:
http://docs.marklogic.com/REST/PUT/v1/documents
If you want to execute some custom logic at the same time a document is written, one simple approach is to specify a transform that performs the side-effect action and simply passes through the document unchanged:
http://docs.marklogic.com/guide/rest-dev/transforms
If your custom logic must handle the write, consider using the PUT method:
http://docs.marklogic.com/REST/PUT/v1/resources/%5Bname%5D
When writing a single document, you specify the mime type that identifies the document format. When writing a batch of documents, you should package the batch as a multipart/mixed payload in which each part specifies the mime type for the document format.
When using a REST extension, you don't need to interact with HTTP. The REST API does that for you, getting the document and passing it to your function. You just write a function that has the expected signature:
http://docs.marklogic.com/guide/rest-dev/extensions#id_75991
And install the library module with the function:
http://docs.marklogic.com/guide/rest-dev/extensions#id_59112
Hoping that helps,
Upvotes: 3