remote-sources.mdx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ---
  2. sidebar_position: 1
  3. slug: /remote-sources
  4. ---
  5. import Tabs from '@theme/Tabs';
  6. import TabItem from '@theme/TabItem';
  7. import UppyCdnExample from '/src/components/UppyCdnExample';
  8. # Remote sources
  9. `@uppy/remote-sources` is a preset plugin (meaning it bundles and sets up other
  10. plugins) to add all the available remote sources, such Instagram, Google Drive,
  11. Dropbox, and others to Uppy Dashboard in one package.
  12. :::note
  13. Remote Sources requires Dashboard and automatically installs all its plugins to
  14. it.
  15. :::
  16. ## When should I use it?
  17. `@uppy/remote-sources` aims to simplify the setup for adding Companion plugins,
  18. when you want to share the configuration between plugins. If you want your users
  19. to upload files from any of the remote sources that Uppy offers, this plugin is
  20. recommended.
  21. A [Companion](/docs/companion) instance is required for the Remote Sources
  22. plugin to work. Companion handles authentication with the remote services (such
  23. as Facebook, Dropbox, etc.), downloads the files, and uploads them to the
  24. destination. This saves the user bandwidth, especially helpful if they are on a
  25. mobile connection.
  26. You can self-host Companion or get a hosted version with any
  27. [Transloadit plan](https://transloadit.com/pricing/).
  28. ## Install
  29. <Tabs>
  30. <TabItem value="npm" label="NPM" default>
  31. ```shell
  32. npm install @uppy/remote-sources
  33. ```
  34. </TabItem>
  35. <TabItem value="yarn" label="Yarn">
  36. ```shell
  37. yarn add @uppy/remote-sources
  38. ```
  39. </TabItem>
  40. <TabItem value="cdn" label="CDN">
  41. <UppyCdnExample>
  42. {`
  43. import { RemoteSources } from "{{UPPY_JS_URL}}"
  44. const RemoteSources = new Uppy().use(RemoteSources)
  45. `}
  46. </UppyCdnExample>
  47. </TabItem>
  48. </Tabs>
  49. ## Use
  50. ```js {10} showLineNumbers
  51. import Uppy from '@uppy/core';
  52. import Dashboard from '@uppy/dashboard';
  53. import RemoteSources from '@uppy/remote-sources';
  54. import '@uppy/core/dist/style.min.css';
  55. import '@uppy/dashboard/dist/style.min.css';
  56. new Uppy();
  57. .use(Dashboard);
  58. .use(RemoteSources, { companionUrl: 'https://your-companion-url' });
  59. ```
  60. ### Use with Transloadit
  61. ```js
  62. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  63. import RemoteSources from '@uppy/remote-sources';
  64. uppy.use(RemoteSources, {
  65. companionUrl: COMPANION_URL,
  66. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  67. });
  68. ```
  69. You may also hit rate limits, because the OAuth application is shared between
  70. everyone using Transloadit.
  71. To solve that, you can use your own OAuth keys with Transloadit’s hosted
  72. Companion servers by using Transloadit Template Credentials. [Create a Template
  73. Credential][template-credentials] on the Transloadit site. Select “Companion
  74. OAuth” for the service, and enter the key and secret for the provider you want
  75. to use. Then you can pass the name of the new credentials to that provider:
  76. ```js
  77. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  78. import RemoteSources from '@uppy/remote-sources';
  79. uppy.use(RemoteSources, {
  80. companionUrl: COMPANION_URL,
  81. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  82. companionKeysParams: {
  83. GoogleDrive: { key: '...', credentialsName: '...' },
  84. Dropbox: { key: '...', credentialsName: '...' },
  85. // ...etc
  86. },
  87. });
  88. ```
  89. ## API
  90. ### Options
  91. #### `id`
  92. A unique identifier for this plugin (`string`, default: `RemoteSources`).
  93. #### `sources`
  94. List of remote sources that will be enabled (`array`, default:
  95. `['Box', 'Dropbox', 'Facebook', 'GoogleDrive','Instagram', 'OneDrive', 'Unsplash', 'Url', 'Zoom']`).
  96. You don’t need to specify them manually or change them, but if you want to alter
  97. the order in which they appear in the Dashboard, or disable some sources, this
  98. option is for you.
  99. ```js
  100. uppy.use(RemoteSources, {
  101. companionUrl: 'https://your-companion-url',
  102. sources: ['Instagram', 'GoogleDrive', 'Unsplash', 'Url'],
  103. });
  104. ```
  105. #### `companionUrl`
  106. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  107. #### `companionHeaders`
  108. Custom headers that should be sent along to [Companion](/docs/companion) on
  109. every request (`object`, default: `{}`).
  110. #### `companionAllowedHosts`
  111. The valid and authorized URL(s)/URL pattern(s) from which OAuth responses should
  112. be accepted (`string | RegExp | Array<string | RegExp>`, Default:
  113. `companionUrl`).
  114. This value can be a `string`, a `RegExp` object, or an array of both.
  115. This is useful when you have your [Companion](/docs/companion) running on
  116. several hosts. Otherwise, the default value, which is `companionUrl`, should do
  117. fine.
  118. #### `companionCookiesRule`
  119. This option correlates to the [`Request.credentials` value][], which tells the plugin
  120. whether to send cookies to [Companion](/docs/companion) (`string`, default: `same-origin`).
  121. #### `target`
  122. DOM element, CSS selector, or plugin to place the drag and drop area into
  123. (`string`, `Element`, `Function`, or `UIPlugin`, default:
  124. [`Dashboard`](/docs/dashboard)).
  125. [`request.credentials` value]:
  126. https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
  127. [template-credentials]:
  128. https://transloadit.com/docs/#how-to-create-template-credentials