Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add download button to binary data #2992

Merged
merged 3 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/editor-ui/src/components/RunData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@

<div class="binary-data-show-data-button-wrapper">
<n8n-button size="small" :label="$locale.baseText('runData.showBinaryData')" class="binary-data-show-data-button" @click="displayBinaryData(index, key)" />
<n8n-button v-if="isDownloadable(index, key)" size="small" type="outline" :label="$locale.baseText('runData.downloadBinaryData')" class="binary-data-show-data-button" @click="downloadBinaryData(index, key)" />
</div>

</div>
Expand All @@ -210,6 +211,7 @@
import VueJsonPretty from 'vue-json-pretty';
import {
GenericValue,
IBinaryData,
IBinaryKeyData,
IDataObject,
INodeExecutionData,
Expand Down Expand Up @@ -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 = '_!^&*';

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br />Displaying it could cause problems.<br /><br />If you do decide to display it, consider avoiding the JSON view."
Expand Down