Skip to content

Commit

Permalink
Update shared.service.ts
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
berglindoma13 authored Jun 3, 2024
1 parent d99d7f3 commit 7ca9b7f
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,47 +242,39 @@ export class SharedTemplateApiService {
)
}

async getAttachmentContentAsBase64(
async getS3File(
application: ApplicationWithAttachments,
attachmentKey: string,
): Promise<string> {
) {
const fileName = (
application.attachments as {
[key: string]: string
}
)[attachmentKey]

const { bucket, key } = AmazonS3URI(fileName)

const uploadBucket = bucket
const file = await this.s3
.getObject({
Bucket: uploadBucket,
Key: key,
})
.promise()
const fileContent = file.Body as Buffer
return file.Body as Buffer
}

async getAttachmentContentAsBase64(
application: ApplicationWithAttachments,
attachmentKey: string,
): Promise<string> {
const fileContent = await this.getS3File(application, attachmentKey)
return fileContent?.toString('base64') || ''
}

async getAttachmentContentAsBlob(
application: ApplicationWithAttachments,
attachmentKey: string,
): Promise<Blob> {
const fileName = (
application.attachments as {
[key: string]: string
}
)[attachmentKey]
const { bucket, key } = AmazonS3URI(fileName)
const uploadBucket = bucket
const file = await this.s3
.getObject({
Bucket: uploadBucket,
Key: key,
})
.promise()
const fileContent = file.Body as Buffer
const fileContent = await this.getS3File(application, attachmentKey)
const blob: Blob = new Blob([fileContent], { type: 'multipart/form-data' })
return blob
}
Expand Down

0 comments on commit 7ca9b7f

Please sign in to comment.