Skip to content

Commit 4163e6c

Browse files
authored
Merge branch 'main' into am/deploy
2 parents 915b0e1 + 0ccbca7 commit 4163e6c

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

.changeset/slimy-camels-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/storage": patch
3+
---
4+
5+
url encode filenames

packages/sdk/test/mock/MockStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export function MockStorage(): ThirdwebStorage {
1010

1111
const uploader = new MockUploader(storage);
1212
const downloader = new MockDownloader(storage);
13-
return new ThirdwebStorage(uploader, downloader);
13+
return new ThirdwebStorage({ uploader, downloader });
1414
}

packages/solana/test/mock/MockStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export function MockStorage(): ThirdwebStorage {
1010

1111
const uploader = new MockUploader(storage);
1212
const downloader = new MockDownloader(storage);
13-
return new ThirdwebStorage(uploader, downloader);
13+
return new ThirdwebStorage({ uploader, downloader });
1414
}

packages/storage/src/core/uploaders/ipfs-uploader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
169169

170170
return {
171171
form,
172-
fileNames,
172+
// encode the file names on the way out (which is what the upload backend expects)
173+
fileNames: fileNames.map((fName) => encodeURIComponent(fName)),
173174
};
174175
}
175176

packages/storage/test/ipfs.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,22 @@ describe("IPFS", async () => {
403403
const uri = await storage.upload(undefined);
404404
expect(uri).to.equal(undefined);
405405
});
406+
407+
it("should successfully upload files with special characters in their file names", async () => {
408+
const bufferWithSpecialCharFileName = {
409+
name: "#specialChar^file$Name.jpg",
410+
data: readFileSync("test/files/0.jpg"),
411+
};
412+
const uri = await storage.upload(bufferWithSpecialCharFileName);
413+
414+
const fileNameEncoded = uri.split("/").at(-1);
415+
416+
expect(fileNameEncoded).to.equal(
417+
encodeURIComponent(bufferWithSpecialCharFileName.name),
418+
);
419+
420+
const res = await storage.download(uri);
421+
422+
expect(res.status).to.equal(200);
423+
});
406424
});

0 commit comments

Comments
 (0)