Skip to content

Commit

Permalink
add base64 to the SVG mime type (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
thdlam authored Oct 27, 2023
1 parent e3cd36e commit ac7fc67
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/file-service/src/utils/fileTypeDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export class FileTypeDetector {

async detect() {
const start = Date.now();
const response = (await this.createCustomConcatStream(this.content)) as CustomConcatStream;
let response = (await this.createCustomConcatStream(this.content)) as CustomConcatStream;

response = this.validateSVGMimeType(response);

const fullStream = response.fileStream;
const fileType = response.fileType;
Expand All @@ -32,6 +34,14 @@ export class FileTypeDetector {
return response;
}

// Need to add base64 to the end of the mime so that the pdf can embed the svg correctly.
validateSVGMimeType(response: CustomConcatStream) {
if (response?.fileType?.mime == 'image/svg+xml') {
response.fileType.mime = `${response?.fileType.mime};base64`;
}
return response;
}

private createCustomConcatStream(readableStream) {
return new Promise((resolve, reject) => {
const customStream = new Readable({
Expand Down

0 comments on commit ac7fc67

Please sign in to comment.