Skip to content

Commit

Permalink
Use ContentDisposition instead of ContentType to control download
Browse files Browse the repository at this point in the history
Fixes OpenRefine#1917. Previously we were using a funky ContentType to attempt
to force a file download rather than display in browser, but this
conflicted with attempts to save UTF-8 which was outside the Basic
Multilingual Plane (BMP).

By switching to ContentDisposition: attachment, which has been
the preferred method for a number of years, we can avoid this conflict.
  • Loading branch information
tfmorris committed Jun 13, 2020
1 parent 3cb1c34 commit e5d560b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Expand Up @@ -100,6 +100,9 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
contentType = exporter.getContentType();
}
response.setHeader("Content-Type", contentType);
String path = request.getPathInfo();
String filename = path.substring(path.lastIndexOf('/') + 1);
response.setHeader("Content-Disposition", "attachment; filename=" + filename);

if (exporter instanceof WriterExporter) {
String encoding = params.getProperty("encoding");
Expand Down
4 changes: 0 additions & 4 deletions main/webapp/modules/core/scripts/project/exporters.js
Expand Up @@ -112,10 +112,6 @@ ExporterManager.stripNonFileChars = function(name) {

ExporterManager.handlers.exportRows = function(format, ext) {
var form = ExporterManager.prepareExportRowsForm(format, true, ext);
$('<input />')
.attr("name", "contentType")
.attr("value", "application/x-unknown") // force download
.appendTo(form);

document.body.appendChild(form);

Expand Down

0 comments on commit e5d560b

Please sign in to comment.