PDF Web SDK Documentation

Comprehensive Guide for Developers: UI & SDK Integration, Configuration, and API Reference

PDF Web SDK
    Preparing search index...

    Interface IFilesProvider

    A source of files the viewer can list and open: the host's recents, a host-owned cloud (customProviders), or a built-in drive.

    The shared UI (FilesSectionTemplate) and mounting logic are driven entirely through this interface, so the sources live in one array and look the same on screen; a concrete provider only maps its own API onto IFileItem and declares its differences through the capability flags below. Every method must be defensive — failures resolve to null rather than throwing, so the UI can tell "failed" from "empty". The one deliberate exception: a user cancel inside a write rejects with an AbortError (see saveOver), so the UI can tell "chose not to" from "could not".

    interface IFilesProvider {
        accountChanged$: Observable<unknown>;
        accountId?: string;
        accountLabel: string;
        canClearAll?: boolean;
        canList?: boolean;
        canRead?: boolean;
        canSave?: boolean;
        iconClass: string;
        iconSvg?: string;
        id: string;
        isConnected: boolean;
        isEnabled: boolean;
        isFlat?: boolean;
        isSticky?: boolean;
        name: string;
        saveHint?: string;
        translateName?: boolean;
        canWriteInto(folder: IFileItem, kind: "file" | "folder"): boolean;
        clearAll(): Promise<void>;
        connect(): Promise<void>;
        createFolder(parent: IFileItem, name: string): Promise<IFileItem>;
        disconnect(): Promise<void>;
        ensureInit(): Promise<boolean>;
        forgetItem(item: IFileItem): Promise<void>;
        getFileAsFile(
            item: IFileItem,
            onProgress?: CloudDownloadProgress,
        ): Promise<File>;
        getThumbnailUrl(item: IFileItem): Promise<string>;
        listFolder(folder?: IFileItem): Promise<IFileItem[]>;
        saveInto(
            folder: IFileItem,
            name: string,
            file: File,
            onProgress: CloudDownloadProgress,
            claims: readonly string[],
        ): Promise<IFileItem>;
        saveOver(
            item: IFileItem,
            file: File,
            onProgress: CloudDownloadProgress,
            claims: readonly string[],
        ): Promise<IFileItem>;
    }
    Index

    Properties

    accountChanged$: Observable<unknown>

    Emits whenever the connection state changes (connect / disconnect).

    accountId?: string

    Stable id of the connected account, where the source has accounts at all — not the display label, which changes when the user renames their profile.

    This is what scopes the recents history: an entry remembers the account it came from and is only listed while that same account is connected, so signing into a second OneDrive shows that account's history rather than another person's dead links. Leave unset for a source with no accounts (the device); it then matches only entries recorded the same way.

    accountLabel: string

    Display label for the connected account, or null.

    canClearAll?: boolean

    True when the source can be emptied (recents' "Clear all"). Read at render time, so it may reflect host config that arrived after construction; the bar then shows the action where a drive shows Disconnect.

    canList?: boolean

    false for write-only targets (the device: a browser cannot enumerate it), which are offered under "Save as" but never get a home-screen tab. Defaults to listable.

    canRead?: boolean

    false when getFileAsFile cannot deliver bytes — the device in a browser page, where nothing on the machine is addressable. Read at render time, so it may reflect host config that arrived later. What it gates is the history: an open is only worth recording as a recent if the file can be loaded again. Defaults to readable.

    canSave?: boolean

    True when this source can be written to. Read at render time, so it may reflect host config (or a granted write scope) that arrives after construction. Gates both saveOver and saveInto, and whether the source is offered as a "Save as" target.

    iconClass: string

    pwv-icon-* class for the tab and connect prompt. Empty when iconSvg carries the icon.

    iconSvg?: string

    Sanitized inline <svg> markup, used instead of iconClass when set. Only host-supplied custom clouds use this — built-ins have font glyphs.

    id: string

    Stable identifier, e.g. 'device' | 'onedrive' | 'googledrive'.

    isConnected: boolean

    True when a user account is currently connected. Always true for sticky sources.

    isEnabled: boolean

    True when the host supplied this provider's config.

    isFlat?: boolean

    True when the source has no hierarchy (recents): listFolder ignores its argument and the bar shows no breadcrumb.

    isSticky?: boolean

    True for sources that are always present and have no sign-in flow (recents, customProviders): never offered under + Connect, no Disconnect.

    name: string

    Display name: a brand name, or an i18n key when translateName is set.

    saveHint?: string

    i18n key explaining what choosing this target does, shown where a listable source would show its folders. Only meaningful for a write-only one.

    translateName?: boolean

    True when name is an i18n key rather than a literal brand name.

    Methods

    • Whether a new file ('file', an upload) or a new folder ('folder') may be put into folder — the level on screen, null at the source's top. Asked per level, so the bar can leave out an action that could only fail there.

      Only a source with a level that is not an ordinary directory needs this. NetExplorer's top level lists the account's root spaces, which the platform hands out, so nothing can be created next to them; and the root of a space that is not itself a folder takes a new folder (an administrator's "root folder") but refuses a file outright — hence the kind, which a single flag could not express.

      Omit it and every level of a writable source accepts both, which is what a drive with an ordinary root does.

      Parameters

      Returns boolean

    • Empty the source. Only called when canClearAll is true.

      Returns Promise<void>

    • Start the interactive sign-in flow. No-op for sticky sources.

      Returns Promise<void>

    • Create an empty folder under parent (the source root when null), resolving the folder that was created or null when it failed — the same convention as the save methods, and a user cancel rejects with an AbortError just as they do.

      Its presence, together with canSave, is what puts "Create folder" on the browser bar: a source that cannot make folders (or has none — see isFlat) simply omits it rather than showing a button that can only fail.

      Parameters

      Returns Promise<IFileItem>

    • Disconnect the local session (does not necessarily sign the user out globally). Its presence is what puts the Disconnect action on the source's browser bar — a source whose sign-out lives elsewhere (a connect-only custom source) omits it.

      Returns Promise<void>

    • Lazily load the provider SDK and initialize. Returns false when disabled.

      Returns Promise<boolean>

    • Drop one entry from the listing without touching the file it points at (recents' per-row "Remove"). Its presence is what puts the row menu on the source's items.

      Parameters

      Returns Promise<void>

    • Load a file's bytes as a File (reporting progress when it can), or null on failure. When the source definitively reports the item gone — deleted, moved, no longer shared — it rejects with a NotFoundError DOMException instead: that, and only that, is what lets the recents history drop a dead row without dropping rows on transient failures.

      Parameters

      Returns Promise<File>

    • A displayable thumbnail URL for an item, or null when unavailable.

      Parameters

      Returns Promise<string>

    • Children of a folder (or the root when omitted), or null when the request failed.

      Parameters

      Returns Promise<IFileItem[]>

    • Write a new file into folder (the source root when null) — "Save as". Resolves the item that was created, which is what the next "Save" then overwrites, or null when the save failed; a user cancel rejects with an AbortError, same as saveOver — as is the progress reporting — and claims, same as saveOver's. Set the item's path when the source has a host-side one: that becomes the document's path.

      Parameters

      Returns Promise<IFileItem>

    • Overwrite the item the document was opened from ("Save"). Resolves the item as it now stands — normally the one passed in — or null when the save failed, the same convention as the read methods above. A user cancel (the device's save picker, a host dialog) is not a failure and rejects with an AbortError instead: the caller reports nothing and adopts nothing. onProgress reports the upload as it leaves, same contract as getFileAsFile's — call it when the write is slow enough to have a middle. claims carries the operations the saved contents went through (sdk.IDocumentModel.listDocumentClaims); empty for a file with no document behind it. Both are passed on every call — an implementation is free to declare neither.

      Parameters

      Returns Promise<IFileItem>