Use ContentDisposition instead of ContentType to control download (#2722)
* Use ContentDisposition instead of ContentType to control download Fixes #1197. 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. As part of this, switch to using the "preview" param consistently to control preview vs download rather than the content type. * Switch content type to text/plain Now that we don't need to use ContentType to control download behavior, we can use something more reasonable.
This commit is contained in:
parent
66c409aec6
commit
5f368bc56d
@ -101,6 +101,13 @@ public class ExportRowsCommand extends Command {
|
|||||||
}
|
}
|
||||||
response.setHeader("Content-Type", contentType);
|
response.setHeader("Content-Type", contentType);
|
||||||
|
|
||||||
|
String preview = params.getProperty("preview");
|
||||||
|
if (!"true".equals(preview)) {
|
||||||
|
String path = request.getPathInfo();
|
||||||
|
String filename = path.substring(path.lastIndexOf('/') + 1);
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
|
||||||
|
}
|
||||||
|
|
||||||
if (exporter instanceof WriterExporter) {
|
if (exporter instanceof WriterExporter) {
|
||||||
String encoding = params.getProperty("encoding");
|
String encoding = params.getProperty("encoding");
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class TemplatingExporter implements WriterExporter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
return "application/x-unknown";
|
return "text/plain";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class TemplateConfig {
|
protected static class TemplateConfig {
|
||||||
|
@ -314,12 +314,10 @@ CustomTabularExporterDialog.prototype._postExport = function(preview) {
|
|||||||
.attr("value", encoding)
|
.attr("value", encoding)
|
||||||
.appendTo(form);
|
.appendTo(form);
|
||||||
}
|
}
|
||||||
if (!preview) {
|
|
||||||
$('<input />')
|
$('<input />')
|
||||||
.attr("name", "contentType")
|
.attr("name", "preview")
|
||||||
.attr("value", "application/x-unknown") // force download
|
.attr("value", preview)
|
||||||
.appendTo(form);
|
.appendTo(form);
|
||||||
}
|
|
||||||
|
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
@ -357,14 +357,11 @@ function SqlExporterDialog(options) {
|
|||||||
.attr("value", encoding)
|
.attr("value", encoding)
|
||||||
.appendTo(form);
|
.appendTo(form);
|
||||||
}
|
}
|
||||||
if (!preview) {
|
|
||||||
$('<input />')
|
$('<input />')
|
||||||
.attr("name", "contentType")
|
.attr("name", "preview")
|
||||||
.attr("value", "application/x-unknown") // force download
|
.attr("value", preview)
|
||||||
.appendTo(form);
|
.appendTo(form);
|
||||||
}
|
|
||||||
|
|
||||||
// alert("form::" + form);
|
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
|
|
||||||
window.open(" ", "refine-export");
|
window.open(" ", "refine-export");
|
||||||
|
@ -111,10 +111,6 @@ ExporterManager.stripNonFileChars = function(name) {
|
|||||||
|
|
||||||
ExporterManager.handlers.exportRows = function(format, ext) {
|
ExporterManager.handlers.exportRows = function(format, ext) {
|
||||||
var form = ExporterManager.prepareExportRowsForm(format, true, 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);
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user