From 083f1216837075c369f18650476b2de13e6490d9 Mon Sep 17 00:00:00 2001 From: Dolan Date: Mon, 12 Nov 2018 12:32:07 +0000 Subject: [PATCH 1/2] Add correct docx mime type --- src/export/packer/packer.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/export/packer/packer.ts b/src/export/packer/packer.ts index e85b42c8ea..856f74b59e 100644 --- a/src/export/packer/packer.ts +++ b/src/export/packer/packer.ts @@ -10,21 +10,30 @@ export class Packer { public async toBuffer(file: File): Promise { const zip = await this.compiler.compile(file); - const zipData = (await zip.generateAsync({ type: "nodebuffer" })) as Buffer; + const zipData = (await zip.generateAsync({ + type: "nodebuffer", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + })) as Buffer; return zipData; } public async toBase64String(file: File): Promise { const zip = await this.compiler.compile(file); - const zipData = (await zip.generateAsync({ type: "base64" })) as string; + const zipData = (await zip.generateAsync({ + type: "base64", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + })) as string; return zipData; } public async toBlob(file: File): Promise { const zip = await this.compiler.compile(file); - const zipData = (await zip.generateAsync({ type: "blob" })) as Blob; + const zipData = (await zip.generateAsync({ + type: "blob", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + })) as Blob; return zipData; } From 28fc328cb3fc3426541c2b8ad2153b4f5db78cd1 Mon Sep 17 00:00:00 2001 From: Dolan Date: Mon, 12 Nov 2018 13:03:17 +0000 Subject: [PATCH 2/2] Add more packer tests --- src/export/packer/packer.spec.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/export/packer/packer.spec.ts b/src/export/packer/packer.spec.ts index 110089da01..b61165ab46 100644 --- a/src/export/packer/packer.spec.ts +++ b/src/export/packer/packer.spec.ts @@ -46,4 +46,24 @@ describe("Packer", () => { }); }); }); + + describe("#toBase64String()", () => { + it("should create a standard docx file", async function() { + this.timeout(99999999); + const str = await packer.toBase64String(file); + + assert.isDefined(str); + assert.isTrue(str.length > 0); + }); + + it("should handle exception if it throws any", () => { + // tslint:disable-next-line:no-any + const compiler = stub((packer as any).compiler, "compile"); + + compiler.throwsException(); + return packer.toBase64String(file).catch((error) => { + assert.isDefined(error); + }); + }); + }); });