| 1 | import { apiClient, apiErrorMessage } from "@/lib/api/client"; |
| 2 | |
| 3 | /** Sends a file's bytes straight from the browser to the API, which streams them to storage. A server action would buffer the whole file and cap it at its body limit. */ |
| 4 | export async function uploadReleaseAsset |
| 5 | username, |
| 6 | repo, |
| 7 | releaseId, |
| 8 | file, |
| 9 | }: { |
| 10 | username: string |
| 11 | repo: string |
| 12 | releaseId: string |
| 13 | file: File |
| 14 | }) { |
| 15 | const { error |
| 16 | "/api/repositories/{username}/{repo}/releases/{id}/assets", |
| 17 | { |
| 18 | params: { |
| 19 | path: { username, |
| 20 | query: { name: file |
| 21 | }, |
| 22 | // always octet-stream: the API parses JSON and form bodies before they could be streamed |
| 23 | headers: { "Content-Type": |
| 24 | body: file as |
| 25 | bodySerializer: (body) |
| 26 | }, |
| 27 | ); |
| 28 | |
| 29 | if (error) throw |
| 30 | } |