Skip to content
BasiX Media

Drop-in upload widget

One script tag and one element give any page a drag-and-drop upload zone with a progress bar. No build step, no dependencies.

  1. 1.Generate a widget token

    Available from the Starter plan. In Dashboard → Developers → Widget, choose a folder, a maximum file size and an expiry. You get a token and a ready-to-paste snippet. You can also mint tokens from your server, as described in "Upload from the browser without exposing your key".

  2. 2.Paste the snippet

    Any element with data-basix-upload and data-token becomes an upload zone. Optional attributes: data-accept (for example image/*), data-multiple, and data-label for the text shown.

    html
    <div data-basix-upload data-token="YOUR_WIDGET_TOKEN" data-accept="image/*" data-multiple></div>
    <script src="https://basix.media/widget.js" async></script>
  3. 3.Listen for uploads

    Each finished file fires a basix:uploaded event on the element, which bubbles up to document. event.detail holds url, id, path, size, mime and name. basix:progress reports percent, basix:error reports message.

    html
    <script>
      document.addEventListener('basix:uploaded', (event) => {
        console.log('Uploaded:', event.detail.url)
      })
    </script>

Worth knowing

  • The token sits in your page source, so treat it as public: it can only upload, only into its folder, only up to its size limit, and only until it expires.
  • Each token belongs to a dedicated key. Revoke that key in API keys to switch the widget off immediately.
  • Elements added after the page loads are picked up by calling window.BasixWidget.scan().

More recipes

← Standalone documentation

Drop-in upload widget — BasiX