Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): add JSON object upload example and documentation #4796

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions apps/portal/src/app/typescript/v5/storage/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The thirdweb SDK comes built-in with an IPFS uploader and downloader.

### Download from IPFS
## Download from IPFS

```ts
import { download } from "thirdweb/storage";
Expand All @@ -15,7 +15,27 @@ const file = await download({

You can view all of the configuration options in the [full reference](/references/typescript/v5/download).

### Upload to IPFS
## Upload to IPFS

### Uploading JSON objects

```ts
import { upload } from "thirdweb/storage";

const uris = await upload({
client,
files: [
{
name: "something",
data: {
hello: "world",
},
},
],
});
```

### Uploading files

```ts
import { upload } from "thirdweb/storage";
Expand Down
19 changes: 19 additions & 0 deletions packages/thirdweb/src/storage/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ type UploadReturnType<TFiles extends UploadableFile[]> = TFiles extends {
* @returns A promise that resolves to the uploaded file URI or URIs (when passing multiple files).
* @throws An error if the upload fails.
* @example
*
* ### Uploading JSON objects
*
* ```ts
* import { upload } from "thirdweb/storage";
* const uri = await upload({
* client,
* files: [
* {
* name: "something",
* data: {
* hello: "world",
* },
* },
* ],
* });
*
* ### Uploading files
*
* ```ts
* import { upload } from "thirdweb/storage";
* const uri = await upload({
Expand Down