Skip to content

Commit

Permalink
Merge pull request #3 from zirkelc/fix-deserialize-payload
Browse files Browse the repository at this point in the history
fix: check content type with startswith
  • Loading branch information
zirkelc authored Oct 7, 2024
2 parents 477c2d4 + 3fa55e9 commit 79bcee7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-tigers-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"middy-store-s3": patch
---

fix: use startsWith instead of equals to check content type
5 changes: 3 additions & 2 deletions packages/store-s3/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ export class S3Store implements StoreInterface<unknown, S3Reference> {
): Promise<unknown> {
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");

Expand Down

0 comments on commit 79bcee7

Please sign in to comment.