Create Document Action to Download JSON File of Document
Has anyone created a document action in WebUI to download the JSON file of the document being viewed (or selected)? The Nuxeo Plugin for Chrome has a feature similar to this (it isn't downloaded, just thrown in a tab), but it would be very useful to have an action to download the JSON, or even have it be one of the options for the export action. I'm not really sure how to go about this yet, so if someone has already done it I would love to get some guidance.
Thanks.
Yes you can create an action to download anything you want really. You can see an example in nuxeo-operation-button
:
When viewing a document in WebUI, you already have the document-as-JSON bound to the document
property. I.e. when you define your action just make sure to bind document
. So the trick is to convert that to a blob and download it. This is just a JavaScript exercise, nothing to do with Nuxeo in particular. Edit to add: if you're not happy with the contents of document
(maybe it's missing a schema or some such) you can instead use the nuxeo-document
element to fetch anything else you'd need:
https://www.webcomponents.org/element/nuxeo/nuxeo-elements/elements/nuxeo-document
You could also extend the export service to do a JSON export but this would require customization.
JSON.stringify(document, null, 4)
and it works well for our purposes. I will likely add an option to download the JSON as a file, but we haven't had a need for that yet.Hello,
There is no default automation operation for that but I guess the Browser Extension is simply using the document id endpoint: https://doc.nuxeo.com/rest-api/1/document-id-endpoint/. So idea would be to wrap the REST API call within an operation, and expose it in studio to reuse it from a button.
Have a great day