fix S3 URL escaping (#14220)

This commit is contained in:
Pedro Guzman
2025-12-04 22:03:17 +01:00
committed by GitHub
parent b7adfb225b
commit 56ed9cf9f7
2 changed files with 18 additions and 1 deletions

View File

@@ -99,6 +99,23 @@ describe.skip("S3 File Plugin", () => {
})
})
it("uploads a file with special URL characters in the name", async () => {
const fileContent = await fs.readFile(fixtureImagePath)
const fixtureAsBinary = fileContent.toString("base64")
const resp = await s3Service.upload({
filename: "cat?photo.jpg",
mimeType: "image/jpeg",
content: fixtureAsBinary,
access: "private",
})
expect(resp).toEqual({
key: expect.stringMatching(/tests\/catphoto.*\.jpg/),
url: expect.stringMatching(/https:\/\/.*\/cat%3Fphoto.*\.jpg/),
})
})
it("gets a presigned upload URL and uploads a file successfully", async () => {
const fileContent = await fs.readFile(fixtureImagePath)
const fixtureAsBinary = fileContent.toString("binary")

View File

@@ -160,7 +160,7 @@ export class S3FileService extends AbstractFileProviderService {
}
return {
url: `${this.config_.fileUrl}/${encodeURI(fileKey)}`,
url: `${this.config_.fileUrl}/${encodeURIComponent(fileKey)}`,
key: fileKey,
}
}