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
@ -100,6 +100,13 @@ public class ExportRowsCommand extends Command {
|
||||
contentType = exporter.getContentType();
|
||||
}
|
||||
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) {
|
||||
String encoding = params.getProperty("encoding");
|
||||
|
@ -57,7 +57,7 @@ public class TemplatingExporter implements WriterExporter {
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "application/x-unknown";
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
protected static class TemplateConfig {
|
||||
|
@ -314,13 +314,11 @@ CustomTabularExporterDialog.prototype._postExport = function(preview) {
|
||||
.attr("value", encoding)
|
||||
.appendTo(form);
|
||||
}
|
||||
if (!preview) {
|
||||
$('<input />')
|
||||
.attr("name", "contentType")
|
||||
.attr("value", "application/x-unknown") // force download
|
||||
.appendTo(form);
|
||||
}
|
||||
|
||||
$('<input />')
|
||||
.attr("name", "preview")
|
||||
.attr("value", preview)
|
||||
.appendTo(form);
|
||||
|
||||
document.body.appendChild(form);
|
||||
|
||||
window.open(" ", "refine-export");
|
||||
|
@ -357,14 +357,11 @@ function SqlExporterDialog(options) {
|
||||
.attr("value", encoding)
|
||||
.appendTo(form);
|
||||
}
|
||||
if (!preview) {
|
||||
$('<input />')
|
||||
.attr("name", "contentType")
|
||||
.attr("value", "application/x-unknown") // force download
|
||||
.appendTo(form);
|
||||
}
|
||||
|
||||
// alert("form::" + form);
|
||||
$('<input />')
|
||||
.attr("name", "preview")
|
||||
.attr("value", preview)
|
||||
.appendTo(form);
|
||||
|
||||
document.body.appendChild(form);
|
||||
|
||||
window.open(" ", "refine-export");
|
||||
|
@ -111,10 +111,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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user