From 3fa55e921ecbcb12f75099ac03f9608ab77cf223 Mon Sep 17 00:00:00 2001 From: zirkelc Date: Mon, 7 Oct 2024 08:33:52 +0200 Subject: [PATCH] fix: check content type with startswith --- .changeset/eleven-tigers-double.md | 5 +++++ packages/store-s3/src/store.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/eleven-tigers-double.md diff --git a/.changeset/eleven-tigers-double.md b/.changeset/eleven-tigers-double.md new file mode 100644 index 0000000..30aa4ca --- /dev/null +++ b/.changeset/eleven-tigers-double.md @@ -0,0 +1,5 @@ +--- +"middy-store-s3": patch +--- + +fix: use startsWith instead of equals to check content type diff --git a/packages/store-s3/src/store.ts b/packages/store-s3/src/store.ts index 8296588..a73cd82 100644 --- a/packages/store-s3/src/store.ts +++ b/packages/store-s3/src/store.ts @@ -203,14 +203,15 @@ export class S3Store implements StoreInterface { ): Promise { const { Body, ContentType } = result; - if (ContentType === "text/plain") { + // TODO check for charset encoding + if (ContentType?.startsWith("text/plain")) { const payload = await Body?.transformToString("utf-8"); if (payload === undefined) throw new Error("Payload is undefined"); return payload as unknown; } - if (ContentType === "application/json") { + if (ContentType?.startsWith("application/json")) { const payload = await Body?.transformToString("utf-8"); if (payload === undefined) throw new Error("Payload is undefined");