Skip to content

Commit 56ed9cf

Browse files
authored
fix S3 URL escaping (medusajs#14220)
1 parent b7adfb2 commit 56ed9cf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/modules/providers/file-s3/integration-tests/__tests__/services.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ describe.skip("S3 File Plugin", () => {
9999
})
100100
})
101101

102+
it("uploads a file with special URL characters in the name", async () => {
103+
const fileContent = await fs.readFile(fixtureImagePath)
104+
const fixtureAsBinary = fileContent.toString("base64")
105+
106+
const resp = await s3Service.upload({
107+
filename: "cat?photo.jpg",
108+
mimeType: "image/jpeg",
109+
content: fixtureAsBinary,
110+
access: "private",
111+
})
112+
113+
expect(resp).toEqual({
114+
key: expect.stringMatching(/tests\/catphoto.*\.jpg/),
115+
url: expect.stringMatching(/https:\/\/.*\/cat%3Fphoto.*\.jpg/),
116+
})
117+
})
118+
102119
it("gets a presigned upload URL and uploads a file successfully", async () => {
103120
const fileContent = await fs.readFile(fixtureImagePath)
104121
const fixtureAsBinary = fileContent.toString("binary")

packages/modules/providers/file-s3/src/services/s3-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class S3FileService extends AbstractFileProviderService {
160160
}
161161

162162
return {
163-
url: `${this.config_.fileUrl}/${encodeURI(fileKey)}`,
163+
url: `${this.config_.fileUrl}/${encodeURIComponent(fileKey)}`,
164164
key: fileKey,
165165
}
166166
}

0 commit comments

Comments
 (0)