Skip to main content

Box

The @uppy/box plugin lets users import files from their Box account.

tip

Try out the live example or take it for a spin in CodeSandbox.

When should I use this?

When you want to let users import files from their Box account.

A Companion instance is required for the Box plugin to work. Companion handles authentication with Box, downloads the files, and uploads them to the destination. This saves the user bandwidth, especially helpful if they are on a mobile connection.

You can self-host Companion or get a hosted version with any Transloadit plan.

npm install @uppy/box

Use

Using Box requires setup in both Uppy and Companion.

Use in Uppy

import Uppy from '@uppy/core';
import Dashboard from '@uppy/dashboard';
import Box from '@uppy/box';

import '@uppy/core/dist/style.min.css';
import '@uppy/dashboard/dist/style.min.css';

new Uppy().use(Dashboard, { inline: true, target: '#dashboard' }).use(Box, {
target: Dashboard,
companionUrl: 'https://your-companion.com',
});

Use in Companion

You can create a Box App on the Box Developers site.

Things to note:

  • Choose Custom App and select the Standard OAuth 2.0 (User Authentication) app type.
  • You must enable full write access, or you will get 403 when downloading files

You’ll be redirected to the app page. This page lists the client ID (app key) and client secret (app secret), which you should use to configure Companion.

The app page has a "Redirect URIs" field. Here, add:

https://$YOUR_COMPANION_HOST_NAME/box/redirect

If you are using Transloadit hosted Companion:

https://api2.transloadit.com/companion/box/redirect

You can only use the integration with your own account initially. Make sure to apply for production status on the app page before you publish your app, or your users will not be able to sign in!

Configure the Box key and secret. With the standalone Companion server, specify environment variables:

export COMPANION_BOX_KEY="Box API key"
export COMPANION_BOX_SECRET="Box API secret"

When using the Companion Node.js API, configure these options:

companion.app({
providerOptions: {
box: {
key: 'Box API key',
secret: 'Box API secret',
},
},
});

API

Options

id

A unique identifier for this plugin (string, default: 'Box').

title

Title / name shown in the UI, such as Dashboard tabs (string, default: 'Box').

target

DOM element, CSS selector, or plugin to place the drag and drop area into (string or Element, default: null).

companionUrl

URL to a Companion instance (string, default: null).

companionHeaders

Custom headers that should be sent along to Companion on every request (Object, default: {}).

companionAllowedHosts

The valid and authorised URL(s) from which OAuth responses should be accepted (string or RegExp or Array, default: companionUrl).

This value can be a string, a RegExp pattern, or an Array of both. This is useful when you have your Companion running on several hosts. Otherwise, the default value should do fine.

companionCookiesRule

This option correlates to the RequestCredentials value (string, default: 'same-origin').

This tells the plugin whether to send cookies to Companion.

locale

export default {
strings: {
pluginNameBox: 'Box',
},
};