Skip to main content
The File Browser is a media library in your page: a customer browses their folders and files, filters them by kind, searches and sorts, uploads by dropping files, and picks the files your page needs (see it in the gallery). By default the files are the customer’s own, kept in your own storage. Or the files are yours: give it your own media library and it lists, uploads, renames and deletes your files, with no Widgetic session at all. Like every piece, it is mounted with the UI SDK. Its editor session needs the surface files, and nothing at all when you give it your own media library. Installing the SDK, tokens, the theme, the language and the Content Security Policy are the same for every piece, and are on the UI Components page. This page covers what is specific to the File Browser.

Options

Events

  • One File Browser per page. A second one is refused with a clear message. Unmount the first before you mount another.
  • A file over 10 MB. An editor session cannot use the resumable upload, so a file over 10 MB is refused with a message instead of being sent.

Show your own media library

If your platform already has a media library (a CMS, an S3 bucket, a DAM), give the File Browser plain functions that read and write it. Your customers browse, upload and pick from your files with the same screen. The piece then never talks to Widgetic, so there is no session to make and no getToken.
  • A failure inside your functions is reported through the error event with fatal: false. The File Browser shows the customer a list that cannot be read (with “Try again”), an upload that fails (in the upload panel) and a rename or delete that your library refuses (in a pop-up, with your library’s sentence under it): the file stays as it was, and your page hears of it as well, so use the event for your log, not for a second message. The code is MEDIA_LIBRARY_ plus UNAUTHORIZED, FORBIDDEN, NOT_FOUND, NETWORK, INVALID_RESPONSE, NOT_SUPPORTED or FAILED, and action says what the customer was doing (load, upload, rename or delete). Throw an error with a status property (a failed fetch response) and it is sorted for you.
  • Everything your functions return is checked before it is shown. A file without an id, a name or a usable address is skipped with a console warning rather than breaking the list.
  • The url of a file is what a widget stores and shows. Once your customer saves or publishes, everyone who sees the widget loads that address, not only the customer who picked it: give one that stays valid and needs no sign-in. A link that expires after a few minutes, or one that checks a cookie, breaks the published widget. Widgetic keeps the id with the file only so that the picker shows it as selected when it is opened again.
  • The Composition Editor and the Widget Creator take the same mediaLibrary: their file pickers then show your files. When you also give upload, the Widget Creator’s chat attachments and the pictures dropped on its canvas call it too, once per file, with purpose set to 'chat' or 'canvas' (the pickers pass 'field').
  • Text, PDF and font previews read the file with a script, so a file on another website needs an Access-Control-Allow-Origin header for your page’s origin. Pictures, audio and video are shown without it.
The types of your library and of the files it handles are exported from @widgetic/ui-sdk (PartnerMediaLibrary, MediaLibraryFile, PickFileFn and PickFileRequest among them), so your functions are checked when you write them.

Your own file picker for the editors

The Composition Editor and the Widget Creator open the File Browser when a file field needs a file. If your platform already has a picker of its own, give them pickFile and they call it instead:
  • accept lists the file types the field allows (['image/*'], for example), and ['*/*'] when it names none. multiple is false for the file fields of a widget, and a field takes the first file of the list you return. signal aborts when the customer closes the editor or starts another pick.
  • Return [], or reject with an AbortError, when the customer cancelled. Any other rejection is written to the console once and counts as nothing picked: the field stays as it was and the customer sees nothing, so say it in your own picker.
  • A result that is not a list is ignored with a warning in the console, and so is an entry that has no id or no url.
  • pickFile serves file fields only. A chat attachment and a picture dropped on the Widget Creator’s canvas go through mediaLibrary.upload when you give one.

Next Steps

Editor Sessions

Make the token on your server

UI Components

The SDK, tokens, the look and the language of every piece

Storage

Where your customers’ uploads are kept

Content Security Policy

What your page has to allow