1
0
mirror of https://github.com/bitwarden/web synced 2025-12-06 00:03:28 +00:00

set blob type

This commit is contained in:
Kyle Spearrin
2018-10-30 09:54:14 -04:00
parent 5ae776309d
commit ec3e92fc19
2 changed files with 27 additions and 1 deletions

2
jslib

Submodule jslib updated: aa0b274f8f...a98a8bda9b

View File

@@ -107,6 +107,31 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void {
let blob: Blob = null;
let type: string = null;
const fileNameLower = fileName.toLowerCase();
if (fileNameLower.endsWith('.pdf')) {
type = 'application/pdf';
} else if (fileNameLower.endsWith('.xlsx')) {
type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
} else if (fileNameLower.endsWith('.docx')) {
type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
} else if (fileNameLower.endsWith('.pptx')) {
type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
} else if (fileNameLower.endsWith('.csv')) {
type = 'text/csv';
} else if (fileNameLower.endsWith('.png')) {
type = 'image/png';
} else if (fileNameLower.endsWith('.jpg') || fileNameLower.endsWith('.jpeg')) {
type = 'image/jpeg';
} else if (fileNameLower.endsWith('.gif')) {
type = 'image/gif';
}
if (type != null) {
blobOptions = blobOptions || {};
if (blobOptions.type == null) {
blobOptions.type = type;
}
}
if (blobOptions != null && !this.isIE()) {
blob = new Blob([blobData], blobOptions);
} else {
@@ -119,6 +144,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
a.href = win.URL.createObjectURL(blob);
a.download = fileName;
a.style.position = 'fixed';
a.target = '_blank';
win.document.body.appendChild(a);
a.click();
win.document.body.removeChild(a);