fix(core): Fix object store support for non-latin chars (#17383)

Co-authored-by: easy <e@mpnew.com>
This commit is contained in:
Iván Ovejero
2025-07-16 21:11:57 +02:00
committed by GitHub
parent 1e82350963
commit 550339ed18
2 changed files with 31 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {
DeleteObjectCommand,
DeleteObjectsCommand,
@@ -178,6 +179,33 @@ describe('ObjectStoreService', () => {
});
});
it('should encode filename with non-ASCII characters in metadata', async () => {
const metadata = {
fileName: 'Order Form - Gunes Ekspres Havacılık A.Ş.',
mimeType: 'text/plain',
};
mockS3Send.mockResolvedValueOnce({});
await objectStoreService.put(fileId, mockBuffer, metadata);
const commandCaptor = captor<PutObjectCommand>();
expect(mockS3Send).toHaveBeenCalledWith(commandCaptor);
const command = commandCaptor.value;
expect(command).toBeInstanceOf(PutObjectCommand);
expect(command.input).toEqual({
Bucket: 'test-bucket',
Key: fileId,
Body: mockBuffer,
ContentLength: mockBuffer.length,
ContentMD5: 'yh6gLBC3w39CW5t92G1eEQ==',
ContentType: 'text/plain',
Metadata: {
filename: 'Order%20Form%20-%20Gunes%20Ekspres%20Havac%C4%B1l%C4%B1k%20A.%C5%9E.',
},
});
});
it('should throw an error on request failure', async () => {
const metadata = { fileName: 'file.txt', mimeType: 'text/plain' };

View File

@@ -107,7 +107,7 @@ export class ObjectStoreService {
};
if (metadata.fileName) {
params.Metadata = { filename: metadata.fileName };
params.Metadata = { filename: encodeURIComponent(metadata.fileName) };
}
if (metadata.mimeType) {
@@ -174,7 +174,8 @@ export class ObjectStoreService {
// Add metadata with the expected prefix format
if (response.Metadata) {
Object.entries(response.Metadata).forEach(([key, value]) => {
headers[`x-amz-meta-${key.toLowerCase()}`] = value;
headers[`x-amz-meta-${key.toLowerCase()}`] =
key === 'filename' ? decodeURIComponent(value) : value;
});
}