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 nogetToken.
- A failure inside your functions is reported through the
errorevent withfatal: 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 arenameordeletethat 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 isMEDIA_LIBRARY_plusUNAUTHORIZED,FORBIDDEN,NOT_FOUND,NETWORK,INVALID_RESPONSE,NOT_SUPPORTEDorFAILED, andactionsays what the customer was doing (load,upload,renameordelete). Throw an error with astatusproperty (a failedfetchresponse) 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
urlof 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 theidwith 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 giveupload, the Widget Creator’s chat attachments and the pictures dropped on its canvas call it too, once per file, withpurposeset 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-Originheader for your page’s origin. Pictures, audio and video are shown without it.
@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 thempickFile and they call it instead:
acceptlists the file types the field allows (['image/*'], for example), and['*/*']when it names none.multipleisfalsefor the file fields of a widget, and a field takes the first file of the list you return.signalaborts when the customer closes the editor or starts another pick.- Return
[], or reject with anAbortError, 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
idor nourl. pickFileserves file fields only. A chat attachment and a picture dropped on the Widget Creator’s canvas go throughmediaLibrary.uploadwhen 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