Skip to content

Commit

Permalink
fix: check content type with startswith
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed Oct 7, 2024
1 parent 477c2d4 commit 3fa55e9
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 3fa55e9

Please sign in to comment.