dropbox.mdx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ---
  2. slug: /dropbox
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. import UppyCdnExample from '/src/components/UppyCdnExample';
  7. # Dropbox
  8. The `@uppy/dropbox` plugin lets users import files from their
  9. [Dropbox](https://www.dropbox.com) 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. [Dropbox](https://www.dropbox.com) account.
  17. A [Companion](/docs/companion) instance is required for the Dropbox plugin to
  18. work. Companion handles authentication with Dropbox, downloads the files, and
  19. uploads them to the destination. This saves the user bandwidth, especially
  20. helpful if they 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/dropbox
  27. ```
  28. </TabItem>
  29. <TabItem value="yarn" label="Yarn">
  30. ```shell
  31. yarn add @uppy/dropbox
  32. ```
  33. </TabItem>
  34. <TabItem value="cdn" label="CDN">
  35. <UppyCdnExample>
  36. {`
  37. import { Uppy, Dropbox } from "{{UPPY_JS_URL}}"
  38. const uppy = new Uppy()
  39. uppy.use(Dropbox, {
  40. // Options
  41. })
  42. `}
  43. </UppyCdnExample>
  44. </TabItem>
  45. </Tabs>
  46. ## Use
  47. Using Dropbox 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 Dropbox from '@uppy/dropbox';
  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(Dropbox, { companionUrl: 'https://your-companion.com' });
  58. ```
  59. ### Use with Transloadit
  60. ```js
  61. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  62. import Dropbox from '@uppy/dropbox';
  63. uppy.use(Dropbox, {
  64. companionUrl: COMPANION_URL,
  65. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  66. });
  67. ```
  68. You may also hit rate limits, because the OAuth application is shared between
  69. everyone using Transloadit.
  70. To solve that, you can use your own OAuth keys with Transloadit’s hosted
  71. Companion servers by using Transloadit Template Credentials. [Create a Template
  72. Credential][template-credentials] on the Transloadit site. Select “Companion
  73. OAuth” for the service, and enter the key and secret for the provider you want
  74. to use. Then you can pass the name of the new credentials to that provider:
  75. ```js
  76. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  77. import Dropbox from '@uppy/dropbox';
  78. uppy.use(Dropbox, {
  79. companionUrl: COMPANION_URL,
  80. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  81. companionKeysParams: {
  82. key: 'YOUR_TRANSLOADIT_API_KEY',
  83. credentialsName: 'my_companion_dropbox_creds',
  84. },
  85. });
  86. ```
  87. ### Use in Companion
  88. You can create a Dropbox App on the
  89. [Dropbox Developers site](https://www.dropbox.com/developers/apps/create).
  90. Things to note:
  91. - Choose the “Dropbox API”, not the business variant.
  92. - Typically you’ll want “Full Dropbox” access, unless you are absolutely certain
  93. that you need the other one.
  94. You’ll be redirected to the app page. This page lists the app key and app
  95. secret, which you should use to configure Companion as shown above.
  96. The app page has a “Redirect URIs” field. Here, add:
  97. ```
  98. https://$YOUR_COMPANION_HOST_NAME/dropbox/redirect
  99. ```
  100. If you are using Transloadit hosted Companion:
  101. ```
  102. https://api2.transloadit.com/companion/dropbox/redirect
  103. ```
  104. You can only use the integration with your own account initially. Make sure to
  105. apply for production status on the app page before you publish your app, or your
  106. users will not be able to sign in!
  107. Configure the Dropbox key and secret. With the standalone Companion server,
  108. specify environment variables:
  109. ```shell
  110. export COMPANION_DROPBOX_KEY="Dropbox API key"
  111. export COMPANION_DROPBOX_SECRET="Dropbox API secret"
  112. ```
  113. When using the Companion Node.js API, configure these options:
  114. ```js
  115. companion.app({
  116. providerOptions: {
  117. dropbox: {
  118. key: 'Dropbox API key',
  119. secret: 'Dropbox API secret',
  120. },
  121. },
  122. });
  123. ```
  124. ## API
  125. ### Options
  126. #### `id`
  127. A unique identifier for this plugin (`string`, default: `'Dropbox'`).
  128. #### `title`
  129. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  130. `'Dropbox'`).
  131. #### `target`
  132. DOM element, CSS selector, or plugin to place the drag and drop area into
  133. (`string`, `Element`, `Function`, or `UIPlugin`, default:
  134. [`Dashboard`](/docs/dashboard)).
  135. #### `companionUrl`
  136. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  137. #### `companionHeaders`
  138. Custom headers that should be sent along to [Companion](/docs/companion) on
  139. every request (`Object`, default: `{}`).
  140. #### `companionAllowedHosts`
  141. The valid and authorised URL(s) from which OAuth responses should be accepted
  142. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  143. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  144. useful when you have your [Companion](/docs/companion) running on several hosts.
  145. Otherwise, the default value should do fine.
  146. #### `companionCookiesRule`
  147. This option correlates to the
  148. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  149. (`string`, default: `'same-origin'`).
  150. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  151. #### `locale`
  152. ```js
  153. export default {
  154. strings: {
  155. pluginNameDropbox: 'Dropbox',
  156. },
  157. };
  158. ```
  159. [template-credentials]:
  160. https://transloadit.com/docs/#how-to-create-template-credentials