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.

0 votes

2 answers

1228 views

ANSWER



Yes you can create an action to download anything you want really. You can see an example in nuxeo-operation-button:

https://github.com/nuxeo/nuxeo-ui-elements/blob/f03857c5cbe5d49bfca1c06b6a3bf118f1471679/widgets/nuxeo-operation-button.js#L210

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.

0 votes



Thanks for your comment, I must have missed it (years ago). We actually implemented a new document tab that will show the object with 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.
08/12/2022


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

0 votes



Thanks for the response. I'll see what I can do. It does seem odd that there is an export option for XML, but not for JSON. The XML is somewhat close to what I would like, but it wraps many values in CDATA tags which is a bit cumbersome.
06/09/2020

I would say there's no explicit "export" to JSON because this is already the native format of the REST API. You just call the REST API to get your JSON (with the bonus that you have a lot of control over the response, which schemas to fetch, which enrichers to use, etc.).
06/09/2020