This commit is contained in:
19
docs/snippets/wasm/api/error_handling.md
Normal file
19
docs/snippets/wasm/api/error_handling.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```typescript title="WASM"
|
||||
import init, { extractBytes } from "kreuzberg-wasm";
|
||||
|
||||
await init();
|
||||
|
||||
const fileInput = document.getElementById("file") as HTMLInputElement;
|
||||
const file = fileInput.files?.[0];
|
||||
|
||||
if (file) {
|
||||
try {
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
const result = await extractBytes(bytes, file.type || "application/pdf", undefined);
|
||||
console.log(`Extracted: ${result.content.length} characters`);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
console.error("Extraction failed:", message);
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user