Skip to content

Commit

Permalink
Correct the mime-type of exported CSVs (#792)
Browse files Browse the repository at this point in the history
Blobs representing CSV content are generated on the browser which are then exported as downloadables. The mime-types were incorrectly set to text/plain in a few places. This commit changes the mime-type to be text/csv.

Issues Resolved
#640

Signed-off-by: Miki <[email protected]>
  • Loading branch information
Miki authored Sep 17, 2021
1 parent 02fb746 commit 8618905
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugins/inspector/public/views/data/lib/export_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function exportAsCsv({
csvSeparator,
quoteValues,
}: any) {
const type = 'text/plain;charset=utf-8';
const type = 'text/csv;charset=utf-8';

const csv = new Blob([buildCsv(columns, rows, csvSeparator, quoteValues, valueFormatter)], {
type,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_table/public/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function OsdAggTable(config, RecursionHelper) {
};

self.exportAsCsv = function (formatted) {
const csv = new Blob([self.toCsv(formatted)], { type: 'text/plain;charset=utf-8' });
const csv = new Blob([self.toCsv(formatted)], { type: 'text/csv;charset=utf-8' });
self._saveAs(csv, self.csv.filename);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ describe('Table Vis - AggTable Directive', function () {
'one,two,"with double-quotes("")"' + '\r\n' + '1,2,"""foobar"""' + '\r\n',
]);
expect(call.args[0].opts).toEqual({
type: 'text/plain;charset=utf-8',
type: 'text/csv;charset=utf-8',
});
expect(call.args[1]).toBe('somefilename.csv');
});
Expand Down

0 comments on commit 8618905

Please sign in to comment.