fix: escape non-ascii characters in filenames in s3 file provider (#14209)
* escape non-ascii characters in filenames in s3 file provider * fix url encoding
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import fs from "fs/promises"
|
||||
import axios from "axios"
|
||||
import fs from "fs/promises"
|
||||
import { S3FileService } from "../../src/services/s3-file"
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -82,6 +82,23 @@ describe.skip("S3 File Plugin", () => {
|
||||
})
|
||||
})
|
||||
|
||||
it("uploads a file with non-ascii characters in the name", async () => {
|
||||
const fileContent = await fs.readFile(fixtureImagePath)
|
||||
const fixtureAsBinary = fileContent.toString("base64")
|
||||
|
||||
const resp = await s3Service.upload({
|
||||
filename: "catphoto-か.jpg",
|
||||
mimeType: "image/jpeg",
|
||||
content: fixtureAsBinary,
|
||||
access: "private",
|
||||
})
|
||||
|
||||
expect(resp).toEqual({
|
||||
key: expect.stringMatching(/tests\/catphoto-か.*\.jpg/),
|
||||
url: expect.stringMatching(/https:\/\/.*\/catphoto-%E3%81%8B.*\.jpg/),
|
||||
})
|
||||
})
|
||||
|
||||
it("gets a presigned upload URL and uploads a file successfully", async () => {
|
||||
const fileContent = await fs.readFile(fixtureImagePath)
|
||||
const fixtureAsBinary = fileContent.toString("binary")
|
||||
|
||||
@@ -148,7 +148,7 @@ export class S3FileService extends AbstractFileProviderService {
|
||||
// Note: We could potentially set the content disposition when uploading,
|
||||
// but storing the original filename as metadata should suffice.
|
||||
Metadata: {
|
||||
"x-amz-meta-original-filename": file.filename,
|
||||
"original-filename": encodeURIComponent(file.filename),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -160,7 +160,7 @@ export class S3FileService extends AbstractFileProviderService {
|
||||
}
|
||||
|
||||
return {
|
||||
url: `${this.config_.fileUrl}/${fileKey}`,
|
||||
url: `${this.config_.fileUrl}/${encodeURI(fileKey)}`,
|
||||
key: fileKey,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user