AppView in a box as a Vite plugin thing
hatk.dev
1---
2title: Blobs
3description: Upload binary data via the user's PDS.
4---
5
6## `dev.hatk.uploadBlob`
7
8Upload a binary blob (image, audio, etc.) via the authenticated user's PDS.
9
10- **Type:** Procedure (POST)
11- **Auth:** Required (session cookie or DPoP token)
12- **Content-Type:** `*/*` (set to the blob's MIME type)
13
14### Request
15
16Send the raw binary data as the request body with the appropriate `Content-Type` header.
17
18```bash
19curl -X POST "http://127.0.0.1:3000/xrpc/dev.hatk.uploadBlob" \
20 -H "Authorization: DPoP <token>" \
21 -H "Content-Type: image/jpeg" \
22 --data-binary @photo.jpg
23```
24
25### Client usage
26
27```typescript
28import { callXrpc } from "$hatk/client";
29
30const result = await callXrpc("dev.hatk.uploadBlob", file);
31// result.blob contains the blob reference
32```
33
34### Response
35
36```json
37{
38 "blob": {
39 "$type": "blob",
40 "ref": { "$link": "bafkrei..." },
41 "mimeType": "image/jpeg",
42 "size": 123456
43 }
44}
45```
46
47## Using blobs in records
48
49After uploading, reference the blob in a record field:
50
51```typescript
52import { callXrpc } from "$hatk/client";
53
54const uploadResult = await callXrpc("dev.hatk.uploadBlob", imageFile);
55
56await callXrpc("dev.hatk.createRecord", {
57 collection: "fm.teal.alpha.feed.play",
58 repo: userDid,
59 record: {
60 createdAt: new Date().toISOString(),
61 image: uploadResult.blob,
62 },
63});
64```