File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
packages/modules/providers/file-s3
integration-tests/__tests__ Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @medusajs/file-s3 " : patch
3+ ---
4+
5+ URL-encode S3 object metadata and returned URL
Original file line number Diff line number Diff line change 1- import fs from "fs/promises"
21import axios from "axios"
2+ import fs from "fs/promises"
33import { S3FileService } from "../../src/services/s3-file"
44jest . setTimeout ( 100000 )
55
@@ -82,6 +82,23 @@ describe.skip("S3 File Plugin", () => {
8282 } )
8383 } )
8484
85+ it ( "uploads a file with non-ascii characters in the name" , async ( ) => {
86+ const fileContent = await fs . readFile ( fixtureImagePath )
87+ const fixtureAsBinary = fileContent . toString ( "base64" )
88+
89+ const resp = await s3Service . upload ( {
90+ filename : "catphoto-か.jpg" ,
91+ mimeType : "image/jpeg" ,
92+ content : fixtureAsBinary ,
93+ access : "private" ,
94+ } )
95+
96+ expect ( resp ) . toEqual ( {
97+ key : expect . stringMatching ( / t e s t s \/ c a t p h o t o - か .* \. j p g / ) ,
98+ url : expect . stringMatching ( / h t t p s : \/ \/ .* \/ c a t p h o t o - % E 3 % 8 1 % 8 B .* \. j p g / ) ,
99+ } )
100+ } )
101+
85102 it ( "gets a presigned upload URL and uploads a file successfully" , async ( ) => {
86103 const fileContent = await fs . readFile ( fixtureImagePath )
87104 const fixtureAsBinary = fileContent . toString ( "binary" )
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ export class S3FileService extends AbstractFileProviderService {
148148 // Note: We could potentially set the content disposition when uploading,
149149 // but storing the original filename as metadata should suffice.
150150 Metadata : {
151- "x-amz-meta- original-filename" : file . filename ,
151+ "original-filename" : encodeURIComponent ( file . filename ) ,
152152 } ,
153153 } )
154154
@@ -160,7 +160,7 @@ export class S3FileService extends AbstractFileProviderService {
160160 }
161161
162162 return {
163- url : `${ this . config_ . fileUrl } /${ fileKey } ` ,
163+ url : `${ this . config_ . fileUrl } /${ encodeURI ( fileKey ) } ` ,
164164 key : fileKey ,
165165 }
166166 }
You can’t perform that action at this time.
0 commit comments