-
Type: Task
-
Status: Open
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: QualifiedToSchedule
-
Component/s: Core
-
Tags:
Currently, executing an operation that returns a blob is troublesome, because the request is made via ajax an there is no easy way to trigger the download on the browser. Currently, we are always replicating the same response handling logic to trigger the download, which should be made available to prevent code duplication:
// execute operation _executeOperation: function() { return this.$.operation.execute().then(function(response) { return this._download(response).then(function() { // success this.fire('document-updated'); }.bind(this)); }.bind(this)).catch(function(response) { // something went wrong }.bind(this)); }, // trigger download _download: function(response) { var contentDisposition = response.headers.get('Content-Disposition'); if (contentDisposition) { var filenameMatches = contentDisposition .match(/filename[^;=\n]*=([^;\n]*''([^;\n]*)|[^;\n]*)/).filter(function(match) { return !!match; }); var filename = decodeURI(filenameMatches[filenameMatches.length - 1]); return response.blob().then(function(blob) { if (navigator.msSaveBlob) { // handle IE11 and Edge navigator.msSaveBlob(blob, filename); } else { var a = document.createElement('a'); a.style = 'display: none'; a.download = filename; a.href = URL.createObjectURL(blob); document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(a.href); } }.bind(this)); } else { return Promise.reject(new Error('missing Content-Disposition header')); } }
We're currently using this on nuxeo-template-rendering, but this code should be refactored.
- causes
-
ELEMENTS-1658 nuxeo-operation-button should not download result blob in the background when using async
- Resolved
- is related to
-
ELEMENTS-1314 Fix html to pdf conversion
- Resolved
-
NXP-28478 Bulk download doesn't show progress
- Resolved
-
ELEMENTS-254 Allow operation element to integrate with Web UI
- Resolved