Uploader API: загрузка ассетов по типу
Upload an asset through the pipeline that owns its KIND, instead of whichever tool happens to be asking. Tools call this rather than reaching into their own `config.uploader`, which is why an audio block's cover art reaches your image pipeline instead of the audio endpoint that would reject it. Resolution order for a kind: the tool whose static `assetKind` matches (e.g. `tools.image.config.uploader` for `'image'`), then the editor-level `uploader` config, then a local fallback — a `blob:` URL for files, the URL verbatim for links.
Как получить экземпляр редактора
Методы ниже вызываются на редакторе, созданном через new Blok(). Они доступны после того, как разрешится editor.isReady.
// You already hold the instance returned by the constructor.
const editor = new Blok({ holder: 'editor' });
await editor.isReady;
// Call any API method on it.
editor.caret.setToLastBlock('end');Методы
uploader.uploadByFile(file, ctx)
Promise<{ url: string; fileName?: string }>Store a file and return its URL. `ctx` is `{ kind, tool?, onProgress? }` where `kind` is the ASSET kind, not the requesting tool — they differ whenever a tool holds an asset outside its own media family.
// Inside a custom block tool that holds a thumbnail
const { url } = await this.api.uploader.uploadByFile(file, {
kind: 'image',
tool: 'my-card',
onProgress: (percent) => this.showProgress(percent),
});uploader.uploadByUrl(url, ctx)
Promise<{ url: string }>Re-host an asset the user supplied by URL and return the stored URL. Without an uploader for the kind, the URL is stored verbatim — configure one if a strict `img-src`/`media-src` policy or link rot would break third-party URLs.
const { url } = await this.api.uploader.uploadByUrl(pastedUrl, {
kind: 'image',
tool: 'my-card',
});uploader.isConfigured(kind, method?)
booleanWhether a host uploader handles this kind. False means the caller would get the local fallback — useful for deciding whether an asset is worth uploading at all, e.g. inlining small extracted artwork as a `data:` URL instead.
if (this.api.uploader.isConfigured('image', 'uploadByFile')) {
const { url } = await this.api.uploader.uploadByFile(artwork, { kind: 'image' });
} else {
// no image pipeline — keep it inline rather than minting a doomed blob: URL
}