fileSystem.UploadOptions
Says how a file is uploaded: the HTTP method and headers, as the whole body or a form field, and its progress.
Verwendung
Choose a file and send it
Dieser Typ wird verwendet von fileSystem.upload
import { Button, Text, VStack, fileSystem, mediaPicker, signal, task } from 'kuito';
export default function PhotoUpload() {
const progress = signal(0);
const selected = signal<string | null>(null);
const upload = task(
async () => {
if (!selected.value) {
const result = await mediaPicker.pick({
mediaTypes: ['images'],
maxWidth: 2048,
quality: 0.8,
});
if (result.canceled || !result.assets[0]) return;
selected.value = result.assets[0].uri;
}
progress.value = 0;
const result = await fileSystem.upload('https://example.com/photos', selected.value, {
onProgress: ({ bytes, total }) => {
progress.value = total ? bytes / total : 0;
},
});
if (result.status < 200 || result.status >= 300)
throw new Error(`Upload failed: ${result.status}`);
selected.value = null;
},
{ policy: 'drop' },
);
return (
<VStack padding={24} gap={12}>
<Button disabled={upload.running.value} onPress={() => void upload.run().catch(() => {})}>
{selected.value ? 'Retry upload' : 'Choose photo'}
</Button>
<Text>
{upload.running.value
? `${Math.round(progress.value * 100)}%`
: upload.error.value
? String(upload.error.value)
: ''}
</Text>
</VStack>
);
}Typdeklaration
export type UploadOptions = {
/** Defaults to `'POST'`. */
method?: 'POST' | 'PUT' | 'PATCH';
headers?: Record<string, string>;
/** The file as the whole body, or as one field of a multipart form. Defaults to `'binary'`. */
uploadType?: 'binary' | 'multipart';
/** The form field holding the file. Defaults to `'file'`. */
fieldName?: string;
mimeType?: string;
/** More form fields, sent before the file. */
parameters?: Record<string, string>;
onProgress?: (progress: TransferProgress) => void;
};Mitglieder 7
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
method | "POST" | "PUT" | "PATCH" | Nein | Defaults to 'POST'. |
headers | Record<string, string> | Nein | — |
uploadType | "binary" | "multipart" | Nein | The file as the whole body, or as one field of a multipart form. Defaults to 'binary'. |
fieldName | string | Nein | The form field holding the file. Defaults to 'file'. |
mimeType | string | Nein | — |
parameters | Record<string, string> | Nein | More form fields, sent before the file. |
onProgress | (progress: TransferProgress) => void | Nein | — |
onProgress — Methodensignaturen
Signaturen
(progress: TransferProgress): voidParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
progress | TransferProgress | Ja | — |
Rückgabe
void
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.