box.mdx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. ---
  2. slug: /box
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. import UppyCdnExample from '/src/components/UppyCdnExample';
  7. # Box
  8. The `@uppy/box` plugin lets users import files from their
  9. [Box](https://www.box.com/en-nl/home) account.
  10. :::tip
  11. [Try out the live example](/examples) or take it for a spin in
  12. [StackBlitz](https://stackblitz.com/edit/vitejs-vite-zaqyaf?file=main.js).
  13. :::
  14. ## When should I use this?
  15. When you want to let users import files from their
  16. [Box](https://www.box.com/en-nl/home) account.
  17. A [Companion](/docs/companion) instance is required for the Box plugin to work.
  18. Companion handles authentication with Box, downloads the files, and uploads them
  19. to the destination. This saves the user bandwidth, especially helpful if they
  20. are on a mobile connection.
  21. You can self-host Companion or get a hosted version with any
  22. [Transloadit plan](https://transloadit.com/pricing/).
  23. <Tabs>
  24. <TabItem value="npm" label="NPM" default>
  25. ```shell
  26. npm install @uppy/box
  27. ```
  28. </TabItem>
  29. <TabItem value="yarn" label="Yarn">
  30. ```shell
  31. yarn add @uppy/box
  32. ```
  33. </TabItem>
  34. <TabItem value="cdn" label="CDN">
  35. <UppyCdnExample>
  36. {`
  37. import { Uppy, Box } from "{{UPPY_JS_URL}}"
  38. const uppy = new Uppy()
  39. uppy.use(Box, {
  40. // Options
  41. })
  42. `}
  43. </UppyCdnExample>
  44. </TabItem>
  45. </Tabs>
  46. ## Use
  47. Using Box requires setup in both Uppy and Companion.
  48. ### Use in Uppy
  49. ```js {10-13} showLineNumbers
  50. import Uppy from '@uppy/core';
  51. import Dashboard from '@uppy/dashboard';
  52. import Box from '@uppy/box';
  53. import '@uppy/core/dist/style.min.css';
  54. import '@uppy/dashboard/dist/style.min.css';
  55. new Uppy()
  56. .use(Dashboard, { inline: true, target: '#dashboard' })
  57. .use(Box, { companionUrl: 'https://your-companion.com' });
  58. ```
  59. ### Use in Companion
  60. You can create a Box App on the
  61. [Box Developers site](https://app.box.com/developers/console).
  62. Things to note:
  63. - Choose `Custom App` and select the `Standard OAuth 2.0 (User Authentication)`
  64. app type.
  65. - You must enable full write access, or you will get
  66. [403 when downloading files](https://support.box.com/hc/en-us/community/posts/360049195613-403-error-while-file-download-API-Call)
  67. You’ll be redirected to the app page. This page lists the client ID (app key)
  68. and client secret (app secret), which you should use to configure Companion.
  69. The app page has a `"Redirect URIs"` field. Here, add:
  70. ```
  71. https://$YOUR_COMPANION_HOST_NAME/box/redirect
  72. ```
  73. If you are using Transloadit hosted Companion:
  74. ```
  75. https://api2.transloadit.com/companion/box/redirect
  76. ```
  77. You can only use the integration with your own account initially. Make sure to
  78. apply for production status on the app page before you publish your app, or your
  79. users will not be able to sign in!
  80. Configure the Box key and secret. With the standalone Companion server, specify
  81. environment variables:
  82. ```shell
  83. export COMPANION_BOX_KEY="Box API key"
  84. export COMPANION_BOX_SECRET="Box API secret"
  85. ```
  86. When using the Companion Node.js API, configure these options:
  87. ```js
  88. companion.app({
  89. providerOptions: {
  90. box: {
  91. key: 'Box API key',
  92. secret: 'Box API secret',
  93. },
  94. },
  95. });
  96. ```
  97. ## API
  98. ### Options
  99. #### `id`
  100. A unique identifier for this plugin (`string`, default: `'Box'`).
  101. #### `title`
  102. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  103. `'Box'`).
  104. #### `target`
  105. DOM element, CSS selector, or plugin to place the drag and drop area into
  106. (`string`, `Element`, `Function`, or `UIPlugin`, default:
  107. [`Dashboard`](/docs/dashboard)).
  108. #### `companionUrl`
  109. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  110. #### `companionHeaders`
  111. Custom headers that should be sent along to [Companion](/docs/companion) on
  112. every request (`Object`, default: `{}`).
  113. #### `companionAllowedHosts`
  114. The valid and authorised URL(s) from which OAuth responses should be accepted
  115. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  116. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  117. useful when you have your [Companion](/docs/companion) running on several hosts.
  118. Otherwise, the default value should do fine.
  119. #### `companionCookiesRule`
  120. This option correlates to the
  121. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  122. (`string`, default: `'same-origin'`).
  123. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  124. #### `locale`
  125. ```js
  126. export default {
  127. strings: {
  128. pluginNameBox: 'Box',
  129. },
  130. };
  131. ```