Skip to content

Commit 79fe3cb

Browse files
authored
chore: update sdk docs (#312)
1 parent ab690c2 commit 79fe3cb

File tree

3 files changed

+12
-120
lines changed

3 files changed

+12
-120
lines changed

docs/sdks/tigris/client-uploads.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { upload } from "@tigrisdata/storage/client";
2525

2626
`upload` accepts the following parameters:
2727

28-
- `path`: (Required) A string specifying the path to the object
28+
- `name`: (Required) A string specifying the name of the object
2929
- `body`: (Required) A blob object as File or Blob
3030
- `options`: (Optional) A JSON object with the following optional parameters:
3131

@@ -49,7 +49,7 @@ contains the following properties:
4949
- `contentDisposition`: content disposition of the object
5050
- `contentType`: content type of the object
5151
- `modified`: Last modified date of the object
52-
- `path`: Path to the object
52+
- `name`: Name of the object
5353
- `size`: Size of the object
5454
- `url`: A presigned URL to the object
5555

docs/sdks/tigris/examples.mdx

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -152,60 +152,24 @@ We leverage the
152152
[presigned URLs](/docs/sdks/tigris/using-sdk#presigning-an-object) features to
153153
allow you to upload files directly to Tigris from the client side.
154154

155-
### Multipart upload
156-
157155
<Tabs>
158156
<TabItem value="server" label="Server" default>
159157

160158
```ts
161159
// app/api/upload/route.ts
162160
import { NextRequest, NextResponse } from "next/server";
163-
import {
164-
initMultipartUpload,
165-
getPartsPresignedUrls,
166-
completeMultipartUpload,
167-
UploadAction,
168-
} from "@tigrisdata/storage";
161+
import { handleClientUpload } from "@tigrisdata/storage";
169162

170163
export async function POST(request: NextRequest) {
171164
try {
172-
const { path, operation, action, contentType, uploadId, parts, partIds } =
173-
await request.json();
174-
175-
switch (action) {
176-
case UploadAction.MultipartInit: {
177-
const result = await initMultipartUpload(path, {});
178-
return NextResponse.json({ data: result.data });
179-
}
180-
181-
case UploadAction.MultipartGetParts: {
182-
if (!uploadId || !parts) {
183-
return NextResponse.json(
184-
{ error: "uploadId and parts are required for multipart-parts" },
185-
{ status: 400 },
186-
);
187-
}
188-
const result = await getPartsPresignedUrls(path, parts, uploadId, {});
189-
return NextResponse.json({ data: result.data });
190-
}
191-
192-
case UploadAction.MultipartComplete:
193-
{
194-
if (!uploadId) {
195-
return NextResponse.json(
196-
{ error: "uploadId is required for multipart-complete" },
197-
{ status: 400 },
198-
);
199-
}
200-
const result = await completeMultipartUpload(path, uploadId, partIds);
201-
return NextResponse.json({ data: result.data });
202-
}
203-
204-
return NextResponse.json(
205-
{ error: `Unsupported action: ${action}` },
206-
{ status: 400 },
207-
);
165+
const body = await request.json();
166+
const { data, error } = await handleClientUpload(body);
167+
168+
if (error) {
169+
return NextResponse.json({ error: error.message }, { status: 500 });
208170
}
171+
172+
return NextResponse.json({ data });
209173
} catch (error) {
210174
return NextResponse.json(
211175
{ error: "Failed to process upload request" },
@@ -261,77 +225,3 @@ export default function ClientUpload() {
261225
</TabItem>
262226

263227
</Tabs>
264-
265-
### Simple upload
266-
267-
<Tabs>
268-
<TabItem value="server" label="Server" default>
269-
270-
```ts
271-
// app/api/upload/route.ts
272-
import { NextRequest, NextResponse } from "next/server";
273-
import { getPresignedUrl } from "@tigrisdata/storage";
274-
275-
export async function POST(request: NextRequest) {
276-
try {
277-
const { path, contentType } = await request.json();
278-
const result = await getPresignedUrl(path, {
279-
operation: "put",
280-
expiresIn: 3600, // 1 hour
281-
});
282-
283-
return NextResponse.json({ data: result.data });
284-
} catch (error) {
285-
console.error("Upload error:", error);
286-
return NextResponse.json(
287-
{ error: "Failed to generate presigned URL" },
288-
{ status: 500 },
289-
);
290-
}
291-
}
292-
```
293-
294-
</TabItem>
295-
296-
<TabItem value="client" label="Client">
297-
298-
```tsx
299-
"use client";
300-
301-
import { upload } from "@tigrisdata/storage/client";
302-
import { useState } from "react";
303-
304-
export default function ClientUpload() {
305-
const [progress, setProgress] = useState<number>(0);
306-
const [url, setUrl] = useState<string | null>(null);
307-
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
308-
const file = e.target.files?.[0];
309-
setProgress(0);
310-
if (file) {
311-
const result = await upload(`${file.name}`, file, {
312-
url: "/api/upload",
313-
access: "private",
314-
onUploadProgress: ({ loaded, total, percentage }) => {
315-
setProgress(percentage);
316-
if (percentage === 100) {
317-
setProgress(0);
318-
}
319-
},
320-
});
321-
setUrl(result.url);
322-
}
323-
};
324-
325-
return (
326-
<>
327-
<input type="file" onChange={handleFileChange} />{" "}
328-
{url && <div>Uploaded to: {url}</div>}{" "}
329-
{progress > 0 && progress < 100 && <div>{progress}%</div>}{" "}
330-
</>
331-
);
332-
}
333-
```
334-
335-
</TabItem>
336-
337-
</Tabs>

docs/sdks/tigris/using-sdk.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ list(options?: ListOptions): Promise<TigrisStorageResponse<ListResponse, Error>>
415415

416416
| **Parameter** | **Required** | **Values** |
417417
| ----------------------------------------- | ------------ | ------------------------------------------------------------------------------- |
418+
| delimiter | No | A delimiter is a character that you use to group keys. |
419+
| prefix | No | Limits the items to keys that begin with the specified prefix. |
418420
| limit | No | The maximum number of objects to return. By default, returns up to 100 objects. |
419421
| paginationToken | No | The pagination token to continue listing objects from the previous request. |
420422
| config | No | A configuration object to override the |

0 commit comments

Comments
 (0)