From 13a9db774576a00d4e3ce1988557654d00067073 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Mon, 28 Mar 2022 12:59:53 +0200 Subject: [PATCH] feat(editor): Add download button for binary data (#2992) * :sparkles: Make it possible to download binary data * :zap: Fix lint issues and add support for filesystem mode * :zap: Design adjustment --- packages/editor-ui/src/components/RunData.vue | 27 ++++++++++++++++++- .../src/plugins/i18n/locales/en.json | 3 ++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/editor-ui/src/components/RunData.vue b/packages/editor-ui/src/components/RunData.vue index 8fc8794811fe4..43091926db53c 100644 --- a/packages/editor-ui/src/components/RunData.vue +++ b/packages/editor-ui/src/components/RunData.vue @@ -184,6 +184,7 @@
+
@@ -210,6 +211,7 @@ import VueJsonPretty from 'vue-json-pretty'; import { GenericValue, + IBinaryData, IBinaryKeyData, IDataObject, INodeExecutionData, @@ -242,6 +244,8 @@ import { workflowRun } from '@/components/mixins/workflowRun'; import mixins from 'vue-typed-mixins'; +import { saveAs } from 'file-saver'; + // A path that does not exist so that nothing is selected by default const deselectedPlaceholder = '_!^&*'; @@ -524,6 +528,24 @@ export default mixins( dataItemClicked (path: string, data: object | number | string) { this.state.value = data; }, + isDownloadable (index: number, key: string): boolean { + const binaryDataItem: IBinaryData = this.binaryData[index][key]; + return !!(binaryDataItem.mimeType && binaryDataItem.fileName); + }, + async downloadBinaryData (index: number, key: string) { + const binaryDataItem: IBinaryData = this.binaryData[index][key]; + + let bufferString = 'data:' + binaryDataItem.mimeType + ';base64,'; + if(binaryDataItem.id) { + bufferString += await this.restApi().getBinaryBufferString(binaryDataItem.id); + } else { + bufferString += binaryDataItem.data; + } + + const data = await fetch(bufferString); + const blob = await data.blob(); + saveAs(blob, binaryDataItem.fileName); + }, displayBinaryData (index: number, key: string) { this.binaryDataDisplayVisible = true; @@ -701,7 +723,10 @@ export default mixins( .binary-data-show-data-button-wrapper { margin-top: 1.5em; - text-align: center; + + button { + margin: 0 0.5em 0 0; + } } .label { diff --git a/packages/editor-ui/src/plugins/i18n/locales/en.json b/packages/editor-ui/src/plugins/i18n/locales/en.json index 7850822a1ba78..4405081688b0d 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -753,7 +753,8 @@ "noTextDataFound": "No text data found", "nodeReturnedALargeAmountOfData": "Node returned a large amount of data", "output": "Output", - "showBinaryData": "Show Binary Data", + "downloadBinaryData": "Download", + "showBinaryData": "View", "startTime": "Start Time", "table": "Table", "theNodeContains": "The node contains {numberOfKb} KB of data.
Displaying it could cause problems.

If you do decide to display it, consider avoiding the JSON view."